开玩笑地说,使用Git这种强大的版本管理工具,时刻要记得一句名言“ Know your place!”
Git Phases
Git 最重要的三个 Phases 的理解对了解当前文件处于哪个工作区十分关键
git add
会使当前工作区的更改的文件状态从 unstaged 变成 stagedgit commit
会使当前工作区的更改的文件状态从 staged 变成 committed
下面的 Flowchart 结合常用命令可以清晰地理解
graph TD; A[Working Area - unstaged] --> | git add | B[Staging Area - staged]; B --> | git commit | C[ Repo - commited ];
Quick Book of Git
Staged files
1 | $git add [files] |
Commited Files
1 | $git commit [files] |
Review the log
1 | $git log -p |
Show status
1 | $git status |
Show differences in unstaged area
1 | $git diff |
1 | leon:qzi.github.io leon$ git diff |
--- a
和 --- b
是进行比较的 文件版本a 和 文件版本b
@@
是 Chunk,代表这一个变更的集合块
-
通常代表那行删除或者进行了更改前的内容
+
通常代表那行是增加的或者进行了更改后的内容
如果是全新创建的文件,没有diff
Show differences in staged area
1 | $git diff --staged |
1 | Leon:qzi.github.io leon$ git diff --staged |
Unstaged the files
1 | $git restore [files] |
List branches
1 | $git branch |
Checkout and Create a new branch
1 | $git checkout -b [branch name] |
Switch branch
1 | $git checkout [branch name] |
Git integration with Vscode
Config VSCode as the Editor
1 | $git config --global core.editor "code --wait" |
Install the Gitlens to view the commit message
PressShift + Command + P
, then type Install extentions
enter to find the Gitlens
Gitlens : https://marketplace.visualstudio.com/items?itemName=eamodio.gitlens
Install the Git Graph to view the commit history
PressShift + Command + P
, then type Install extentions
enter to find the Git Graph
or Git history
as a alternative
Git Graph: https://marketplace.visualstudio.com/items?itemName=mhutchie.git-graph
Git History: https://marketplace.visualstudio.com/items?itemName=donjayamanne.githistory
其实我只是想实验 Mermaid 的 flowchart 才写的这篇 つ﹏⊂
To Be Continue …
Reference
用 diff 来检查改动
https://www.git-tower.com/learn/git/ebook/cn/command-line/advanced-topics/diffs