2. Git is a version control system. Distributed version control systems exist
because these systems will "merge" changes together intelligently,
enabling multiple developers to work on a project at the same time.
There are a few distributed version control systems, including Mercurial
and Bazzar. However, Git is by far the most popular.
Git is a command-line tool we can access by typing git in the shell. The
first step in using Git is to initialize a folder as a repository. A repository
(or "repo") tracks multiple versions of the files in the folder, enabling
collaboration.
We can initialize a repository by typing git init inside the folder we
want to use for our project.
3. The typical Git workflow
involves adding files, making
changes, and storing a
checkpoint (or "snapshot") of
those changes. These
checkpoints are called
commits.
Instead of storing every file in
every commit, Git stores the
diff, or the things that change
between commits.
Every project is a sequence of
commits. Commits give us a
powerful way to merge the
changes of multiple team
members together. We can
even restore the repository to
an earlier checkpoint, or
moment in time.
4. committed - The current version of the file has been added to a commit, and Git
has stored it.
staged - The file has been marked for inclusion in the next commit, but hasn't
been committed yet (and Git hasn't stored it yet). You might stage one file
before working on a second file, for example, then commit both files at the same
time when you're done.
modified - The file has been modified since the last commit, but isn't staged yet.
After we make changes to a Git repository, we can run the git status command to
check the state of each file within it. Any files that don't show up in git status are
in the committed state (i.e., don't have unsaved changes).
Files can have one of three states in Git:
5. Before we can make our first commit, we need to tell Git who we are so it
can store that information along with the commit. This step ensures that all of
the members on a team can tell who made a certain commit.
We can do this by running git config. We only need to run this command
once per computer, because Git will save the information.
Git needs two pieces of information about you -- your email address and your
name. You can configure your email with:
git config --global user.email "your.email@domain.com"
You can configure your name with:
git config --global user.name "Your name"
6. To make a commit, we use git commit -m "Commit message here".
The -m flag indicates that we're adding a message, and the text in quotes that
comes after it is the commit message itself. It's customary to make the commit
message something informative, so if we do have to rewind or merge code, it's
obvious what changes we made and when.
we can use git diff to see all of the line differences between the current
and previous version. We can scroll up and down with the arrow keys, and exit
git diff with the q key. If we want to see the differences after we stage a file, we
can use git diff --staged
7. We can pull up a repository's commit history using the git log command. This command will
show us a list of all of the commits to the repository, in descending order by creation date. If the
output is very long, it will allow us to scroll. We can scroll through the log with the up and down
arrows, and use the q key to exit.
We can use git log --stat to see more details about the commits in the git log output.
8. Command
Getting started with Git:
git
Initializing a repo:
git init
Check the state of each file:
git status
Add files to staging area:
git add
Configure identity in Git:
• Configure email
git config --global user.email
"your.email@domain.com"
• Configure name
git config --global user.name
"Your name"
Making a commit
git commit -m "Commit
message here"
Viewing the diff
• View the diff before staged
git diff
• View the diff after staged
git diff --staged
View repo's commit history
git log
9. Docker is basically seen as a tool. It can package our applications and
algorithms along with their dependencies. it makes it easy for us to
replicate our code or our projects, allows us to run them in the cloud or
in other environments, share them across teams, deploy containers to
production and much more.
10. Docker Container
A Docker container is the same idea as a physical container--think of it like a box with an
application in it. Inside the box, the application seems to have a computer all to itself: it
has its own machine name and IP address, and it also has its own disk drive (Windows
containers have their own Windows Registry too). Figure 2.2 shows how the app is boxed
by the container.
11. The application inside the box (container) can’t see anything
outside the box, but the box is running on a computer, and that
computer can also be running lots of other boxes. The applications
in those boxes have their own separate environments (managed by
Docker), but they all share the CPU and memory of the computer,
and they all share the computer’s operating system
12. List all container
docker container ps to list running container
or docker container ps -a to list all container
14. Running a docker container
docker run [docker_image]
You can run containers from locally stored Docker
images. If you use an image that is not on your system,
the software pulls it from the online registry.
15. Run a Container Under a Specific Name
docker container run --name [container_name] [docker_image]
You can check whether you have successfully set a container name by displaying
a list of all containers (running and stopped) with the command:
docker ps -a
17. Exec into a running container
Sometimes, we want to run another process insi. How can we do this? First, we need to know
either the ID or the name of the container, and then we can define which process we want to run
and how we want it to run
docker exec -it [CONTAINER NAME/ID] bash
The -i flag signifies that we want to run the additional process interactively, and -t tells Docker
that we want it to provide us with a TTY (a Terminal emulator) for the command. Finally, the
process we run is bash.
18. OOP
Python Import
Python code is organized into both modules and packages.
In Python, you use the import keyword to make code in
one module available in another. Imports in Python are important
for structuring your code effectively. Using imports properly will
make you more productive, allowing you to reuse code while
keeping your projects maintainable.
19. In practice, a module usually corresponds to
one .py file containing Python code.
The true power of modules is that they can be
imported and reused in other code.
>>> import math
>>> math.pi
3.141592653589793
In the first line, import math, you import the code in
the math module and make it available to use. In the
second line, you access the pi variable within
the math module. math is part of Python’s standard
library, which means that it’s always available to import
when you’re running Python.
Modules Package
You can use a package to further organize your
modules. Note that a package is still a module. As a
user, you usually don’t need to worry about whether
you’re importing a module or a package.
The package will consist of the following
directories and files: