First Lesson
Compare differences for two large files in Linux
Commend: diff -u old_file new_file
Example: old_file.py and new_file.py are two different Python programs:
x = np.linspace(0, 10, 1000)
y = np.sin(x)
plt.plot(x, y)
plt.show()
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 100, 1000)
y = np.sin(x)
plt.plot(x, y)
plt.show()
Runing diff -u old_file.py new_file.py, we have the following result:
jjx323@jjx323-5520:~/Downloads$ diff -u old_file.py new_file.py
--- old_file.py 2019-01-14 21:30:38.081065810 +0800
+++ new_file.py 2019-01-14 21:31:13.696811547 +0800
@@ -1,5 +1,6 @@
import numpy as np
-x = np.linspace(0, 10, 1000)
+import matplotlib.pyplot as plt
+x = np.linspace(0, 100, 1000)
y = np.sin(x)
plt.plot(x, y)
plt.show()
\ No newline at end of file
Minus sign “-” means this line appeared in old_file.py but not in new_file.py, Positive sign “+” means this line appeared in new_file.py but not in old_file.py
Important concepts in Git
-
Git save different versions manually to make every saved version is meaningful.
-
User defined check-points are called "Commits" which is the building blocks for version-control in Git.
-
Navigate to the directory where the code is saved, and type
git log. Then you will get the recent "Commits" that you have made. Each one has an id(yellow line in the following example), author, date and a message associated with it.
Screenshot from 2019-01-15 15-23-35.png
In addition, you can use git diff first_id second_id to check differences between two versions.
-
Each "commit" should address one logical change.
-
Tracking across files, you can submit multiple files at one time.
-
Download repository: download the entire history
Commend:
git clone http://......Example:git clone http://github.com/udacity/asteroids.git
-
git checkout commit_id
-
git workspace
Second Lesson
Compared with the normal folder, there is a hidden file .git in the git repository, which can be seen by commend: ls -a.
Create a repository
To init a git repository, you need the commend: git init.
In the git repository, there are three different spaces.
-
Working directory
You can modify your file here, add new contents, delete old files and so on. -
Staging area
You can submit files temporarily in this area until you want to commit all the files here. Add files to this directory, you need the commend:git add file_name. -
Repository
All the history log have been saved in repository. To submit the files in staging area, you need the commend:git commit.
Compare differences between files
- Compare differences between files in working directory and files in staging area:
git diffwith no other parameters. - Compare differences between files in staging area and files in repository:
git diff --stagedwith no other parameters. - Compare differences between different versions in repository:
git diff commit_id1 commit_id2.
Branch
Git allows you to create labels for your commits. These labels are called Branches.
In the following example, orange words are labels, and a commit can has multiple labels.
Screenshot from 2019-01-19 19-42-32.png
git branch: this commend returns the current branches.
git branch branch_name: this commend create a new branch with branch_name.
git checkout branch_name: this commend switch to the branch with branch_name.
Example:
Screenshot from 2019-01-19 19-54-33.png
Combine branches
Combine branches into a single version.
Merging files: originally there are files A,B,D; Jack makes some changes and finally provide files B,D,E; Rachel makes some changes and finally provide files A,B,C,D. The finally merging files must contain files B,D; files A,C,E are unknown
git merge branch1 branch2: merge branch2 into branch1.
git merge branch2: merge branch2 into the current branch.
Some commends
git reset --hard: reset all the files in working directory and staging area to the most recent commit in repository.









网友评论