美文网首页
Notes for Studying Git

Notes for Studying Git

作者: jjx323 | 来源:发表于2019-01-23 16:48 被阅读0次

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

  1. Git save different versions manually to make every saved version is meaningful.

  2. User defined check-points are called "Commits" which is the building blocks for version-control in Git.

  3. 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.

  1. Each "commit" should address one logical change.

  2. Tracking across files, you can submit multiple files at one time.

  3. Download repository: download the entire history

    Commend: git clone http://......

    Example:git clone http://github.com/udacity/asteroids.git

  4. git checkout commit_id

  5. 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

  1. Compare differences between files in working directory and files in staging area:
    git diff with no other parameters.
  2. Compare differences between files in staging area and files in repository:
    git diff --staged with no other parameters.
  3. 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.

相关文章

  • Notes for Studying Git

    First Lesson Compare differences for two large files in L...

  • [git]git notes

    介绍 VCS(Version Control Systems) 版本控制是一种记录一个或若干文件内容变化,以便将来...

  • Git Notes

    When a requirement of new feature or bugfix is coming Cre...

  • Git Notes

    Cancel the version control by git git init the whole root...

  • Git Notes

    观书有会意处,题其衣裳,以记其事~ 1、拉取远程分支并创建本地分支 使用该方式会在本地新建分支branch_x,并...

  • git notes

    title: git notesdate: 2020-03-07 01:13:12tags: 工具 hexocat...

  • 好玩的shell脚本

    我的总结记录文档: https://github.com/jinboxu/Shell_notes.git 1. 获...

  • studying

    读史使人明智,因为"以史为鉴,可以知兴替" 读诗使人聪慧,因为诗诗最精简美丽的语言 演算使人精密,因为心会和数字一...

  • Git's Notes And Records

    Author: Mikoy Date: 2018-02-04 1. The concepts of git: Gi...

  • git版本控制notes

    在进行文件,代码修改时,为了记录每次的更改以及之后重回更改前的版本,使用版本控制工具是一种很有效的方式。之前使用g...

网友评论

      本文标题:Notes for Studying Git

      本文链接:https://www.haomeiwen.com/subject/edbmdqtx.html