开玩笑地说,使用Git这种强大的版本管理工具,时刻要记得一句名言“ Know your place!”
Git Process Flow
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] |
Show status
1 | $git status |
Review the log
1 | $git log -p |
Git diff in the specific commit
1 | ❯ git log |
Show differences between Woirking Directory and the Staging Area
1 | $git diff |
1 | leon:qzi.github.io leon$ git diff |
--- a
和 --- b
是进行比较的 文件版本a 和 文件版本b
@@
是 Chunk,代表这一个变更的集合块
-
通常代表那行删除或者进行了更改前的内容
+
通常代表那行是增加的或者进行了更改后的内容
如果是全新创建的文件,没有diff
Show differences in Staging Area and HEAD
1 | $git diff --staged |
1 | Leon:qzi.github.io leon$ git diff --staged |
HEAD
HEAD
– is a reference to a specific commit (normally to the the last commit in a local repository).
1 | HEAD 说明: |
Unstaged files
1 | $git restore [files] |
Uncommited files
1 | $git reset –hard |
Untrack files
1 | ❯ git rm -r -n --cached package-lock.json |
-r 表示递归,-n 表示先不删除,只是列出文件。
Basic Branch Mangement
Git graph based on mermaid
%%{init: { 'logLevel': 'debug', 'theme': 'neutral' } }%% gitGraph commit commit branch develop checkout develop commit commit branch feature-v1.0.0 commit commit checkout feature-v1.0.0 commit commit checkout develop merge feature-v1.0.0 checkout main merge develop commit
List branches
1 | ❯ git branch |
Switch to the specific branch
1 | ❯ git checkout master |
Create a new branch
1 | ❯ git branch feature-v2.0.0 |
Checkout and Create a new branch
1 | ❯ git checkout -b [branch name] |
Merge the branch
1 | ❯ git checkout master |
Delete the branch
1 | ❯ git branch |
.gitignore
1 | ❯ touch .gitignore |
Add .idea/
into .gitignore, then it can filter the files and folders under .idea/
Basic Operation of Github
Git clone
Clone from remote repo to local repo
1 | ❯ git clone https://github.com/theme-next/hexo-next-share.git |
Git push
Push the local repo to remote repo
1 | ❯ git push |
Git diff.tool && merge.tool
1 | ❯ git config --global merge.tool vimdiff |
Git integration with Vscode
Config VSCode as the Editor
1 | $git config --global core.editor "code --wait" |
Install the Gitlens to view the committed 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
Test
其实我只是想实验 Mermaid 的 flowchart 才写的这篇 つ﹏⊂
To Be Continue …
Reference
用 diff 来检查改动
https://www.git-tower.com/learn/git/ebook/cn/command-line/advanced-topics/diffs
About Mermaid
https://mermaid-js.github.io/mermaid/#/
git reset 命令
https://www.runoob.com/git/git-reset.html