Git常用命令超级详细(全网最详细)
优质文章,第一时间送达
1.新建代码库
1.1在当前目录新建一个 Git 代码库
$ git init
1.2新建一个目录,将其初始化为 Git 代码库
$ git init [project-name]
1.3下载一个项目和它的整个代码历史
$ git clone [url]
2.配置
Git 的设置文件为.gitconfig,它可以在用户主目录下(全局配置),也可以在项目目录下(项目配置)。
2.1设置提交代码时的用户信息
$ git config [--global] user.name "[name]"
$ git config [--global] user.email "[email address]"
2.2编辑 Git 配置文件
$ vim ~/.gitconfig
2.3显示当前的 Git 配置
$ git config --list
2.4显示当前的 Git 配置
$ cat ~/.gitconfig
3.增加/删除文件
3.1添加指定文件到暂存区
$ git add [file1] [file2] ...
3.2添加指定目录到暂存区,包括子目录
$ git add [dir]
3.3添加当前目录的所有文件到暂存区
$ git add .
3.4删除工作区文件,并且将这次删除放入暂存区
$ git rm 1.txt 2.txt
error: the following files have changes staged in the index:
1.txt
2.txt
(use --cached to keep the file, or -f to force removal)
3.4.1直接删除文件
$ git rm -fr 1.txt
3.4.2停止追踪指定文件,但该文件会保留在工作区
$ git rm --cached [file]
$ git rm --cached 1.txt 2.txt
rm '1.txt'
rm '2.txt'
3.5改名文件,并且将这个改名放入暂存区
$ git mv [file-original] [file-renamed]
4.代码提交
4.1提交暂存区到仓库区
$ git commit -m [message]
4.2提交暂存区的指定文件到仓库区
$ git commit [file1] [file2] ... -m [message]
4.3提交工作区自上次 commit 之后的变化,直接到仓库区
$ git commit -a
4.4提交时显示所有 diff 信息
$ git commit -v
4.5使用一次新的 commit,替代上一次提交如果代码没有任何新变化,则用来改写上一次 commit 的提交信息
$ git commit --amend -m [message]
5.分支
5.1列出所有本地分支
$ git branch
*表示当前分支
5.2列出所有远程分支
$ git branch -r
5.3列出所有本地分支和远程分支
$ git branch -a
5.4新建一个分支,但依然停留在当前分支
$ git branch [branch-name]
5.5新建一个分支,并切换到该分支
$ git checkout -b [branch]
5.6新建一个分支,指向指定 commit
5.6.1查看提交的日志
$ git log
commit 2cb44e585aab4d1b2370a3e42dc6d4070fe217dc (HEAD -> DevOps_RC, origin/master, master, DevOps_Release, DevOps_Dev)
Author: zhangsan <[email protected]>
Date: Sat Jul 10 11:03:12 2021 +0800
修改了ReadMe.md文件,添加了一行说明
commit 89d1d5b198a77deb9096e11b02aec7187221f384
Author: zhangsan <[email protected]>
Date: Sat Jul 10 10:59:09 2021 +0800
:...skipping...
commit 2cb44e585aab4d1b2370a3e42dc6d4070fe217dc (HEAD -> DevOps_RC, origin/master, master, DevOps_Release, DevOps_Dev)
Author: zhangsan <[email protected]>
Date: Sat Jul 10 11:03:12 2021 +0800
修改了ReadMe.md文件,添加了一行说明
commit 89d1d5b198a77deb9096e11b02aec7187221f384
Author: zhangsan <[email protected]>
Date: Sat Jul 10 10:59:09 2021 +0800
添加User文件夹
commit b54962a30b090f02a39fc3c6185750cf07b068ea
Author: zhangsan <[email protected]>
Date: Sat Jul 10 10:58:30 2021 +0800
添加忽略文件
commit e76012d77857841d344ac04893a158e75e8088fc
Author: zhangsan <[email protected]>
Date: Sat Jul 10 10:56:46 2021 +0800
添加Readme.md文件
5.6.2新建一个分支,指向指定 commit ID
$ git branch [branch] [commit]
$ git branch DevOps_V0.3FixBug 89d1d5b198a77deb9096e11b02aec7187221f384
5.7新建一个分支,与指定的本地分支建立追踪关系
$ git branch --track [branch1] [branch2]
$ git branch --track DevOps_RC1 DevOps_RC
5.7.1DevOps_RC,增加一次提交
5.7.2DevOps_RC,再增加一次提交
5.8切换到指定分支,并更新工作区
5.8.1切换到建立追踪的分支DevOps_RC1
$ git checkout [branch-name]
$ git checkout DevOps_RC1
5.8.2从建立追踪的分支拉取最新的变化
$ git pull
5.9新建一个分支,与指定的远程分支建立追踪关系
5.9.1将本地的所有分支及信息全部推送到远程仓库
$ git push -u origin *:*
说明:origin,查看是否配置origin;默认克隆时,自动建立;
5.9.2查看origin信息
$ git remote -v
origin http://192.168.145.88/devops/devops.git (fetch)
origin http://192.168.145.88/devops/devops.git (push)
5.9.3新建一个分支,与指定的远程分支建立追踪关系
$ git branch --track [branch] [remote branch]
$ git branch --track DevOps_RC2 remotes/origin/DevOps_RC1
5.9.4切换到建立追踪关系的新分支DevOps_RC2
$ git checkout DevOps_RC2
Switched to branch 'DevOps_RC2'
Your branch is behind 'origin/DevOps_RC1' by 1 commit, and can be fast-forwarded.
(use "git pull" to update your local branch)
5.9.5使用 git pull 更新本地分支(会拉取建立追踪关系的分支代码)
$ git pull
warning: ----------------- SECURITY WARNING ----------------
warning: | TLS certificate verification has been disabled! |
warning: ---------------------------------------------------
warning: HTTPS connections may not be secure. See https://aka.ms/gcmcore-tlsverify for more information.
warning: ----------------- SECURITY WARNING ----------------
warning: | TLS certificate verification has been disabled! |
warning: ---------------------------------------------------
warning: HTTPS connections may not be secure. See https://aka.ms/gcmcore-tlsverify for more information.
Updating f7ed8ad..c11bb1a
Fast-forward
Readme.md | 1 +
1 file changed, 1 insertion(+)
5.10合并指定分支到当前分支
$ git merge [branch]
$ git merge DevOps_V0.3FixBug
提示文件存在冲突,冲突解决后再提交
5.10.1解决合并产生的冲突
按照冲突提示,修改冲突文件 Readme.md
$ vim Readme.md
5.10.2编辑修改解决冲突
5.10.2.1冲突提示
5.10.2.2冲突解决
5.10.2.3查看当前状态
$ git status
On branch DevOps_RC1
Your branch is up to date with 'origin/DevOps_RC1'.
You have unmerged paths.#有未合并的分支
(fix conflicts and run "git commit")#修复冲突并且运行git commit
(use "git merge --abort" to abort the merge) #使用 git merge --abort终止合并
Unmerged paths:#未合并的分支
(use "git add <file>..." to mark resolution)
both modified: Readme.md
no changes added to commit (use "git add" and/or "git commit -a")
此处我的处理措施是,把合并结果加入当前分支
5.11选择一个 commit,合并进当前分支
$ git cherry-pick [commit]
5.11.1选择别的分支(DevOps_RC1)的一个commit
$ git log
5.11.2切换到另一个项目合并一个提交至此分支的分支
5.11.2.1切换分支(DevOps_Dev)
$ git checkout DevOps_Dev
Switched to branch 'DevOps_Dev'
Your branch is up to date with 'origin/DevOps_Dev'.
5.11.2.2将选定的commit,合并进当前分支
$ git cherry-pick 900d39d30f2487897c1fc09f71c4bd41e1c0cf7a
5.11.2.3查看当前状态
$ git status
5.11.2.4解决冲突
5.12删除分支
$ git branch -d [branch-name]
5.13删除远程分支
5.13.1查看当前分支的详细信息
$ git branch -av
5.13.2删除远程分支
$ git push origin --delete DevOps_RC2
可以看到远程的此分支已经删除了
可以看到远程的此分支已经删除了
5.13.3 删除远程分支
$ git branch -dr remotes/origin/DevOps_RC1
$ git branch -av
6.标签
6.1列出所有 tag
$ git tag
$ git tag -l
DevOps_Dev_V1.0
Dev_V1.0
V0.3FixBug
$ git tag --list
DevOps_Dev_V1.0
Dev_V1.0
V0.3FixBug
6.2新建一个 tag 在当前 commit
$ git tag [tag]$ git tag V0.3FixBug
6.3新建一个 tag 在指定 commit
$ git tag [tag] [commit] -m [message]
$ git tag Dev_V1.0 89d1d5b198a77deb9096e11b02aec7187221f384 -m "初始开发基线"
6.4新建一个tag在当前commit,提交信息为:文件内容
$ git tag DevOps_Dev_V1.0 -F ReleaseNotes.md
6.5查看 tag 信息
$ git show [tag]
$ git show DevOps_Dev_V1.0
6.6提交指定 tag到远程仓库
$ git push [remote] [tag]
$ git push origin V0.3FixBug
6.7提交所有 tag
$ git push [remote] --tags
$ git push origin --tags
6.8基于某个tag创建分支并切换至该分支
$ git checkout -b [branch] [tag]$ git checkout -b DevOps_RC3 V0.3FixBug
7.查看信息
7.1显示有变更的文件
$ git status
On branch DevOps_Dev
Your branch is up to date with 'origin/DevOps_Dev'.
You are currently cherry-picking commit 900d39d.
(fix conflicts and run "git cherry-pick --continue")
(use "git cherry-pick --skip" to skip this patch)
(use "git cherry-pick --abort" to cancel the cherry-pick operation)
Unmerged paths:
(use "git add/rm <file>..." as appropriate to mark resolution)
deleted by us: 3.txt
no changes added to commit (use "git add" and/or "git commit -a")
7.2显示当前分支的版本历史
$ git log
commit 2cb44e585aab4d1b2370a3e42dc6d4070fe217dc (HEAD -> DevOps_Dev, origin/master, origin/DevOps_Release, origin/DevOps_Dev, master, DevOps_Release)
Author: zhangsan <[email protected]>
Date: Sat Jul 10 11:03:12 2021 +0800
修改了ReadMe.md文件,添加了一行说明
commit 89d1d5b198a77deb9096e11b02aec7187221f384 (origin/DevOps_V0.3FixBug)
Author: zhangsan <[email protected]>
Date: Sat Jul 10 10:59:09 2021 +0800
添加User文件夹
commit b54962a30b090f02a39fc3c6185750cf07b068ea
Author: zhangsan <[email protected]>
Date: Sat Jul 10 10:58:30 2021 +0800
添加忽略文件
commit e76012d77857841d344ac04893a158e75e8088fc
Author: zhangsan <[email protected]>
Date: Sat Jul 10 10:56:46 2021 +0800
添加Readme.md文件
7.3显示 commit 历史,以及每次 commit 发生变更的文件
$ git log --stat
commit 1c6e4116363e0dce9a931eeaad1d1dcd470bb673 (HEAD -> DevOps_RC3, tag: V0.3FixBug, origin/DevOps_V0.3FixBug, DevOps_V0.3FixBug)
Author: zhangsan <[email protected]>
Date: Sat Jul 10 14:07:01 2021 +0800
修复了V0.3FixBug
Readme.md | 1 +
1 file changed, 1 insertion(+)
commit 89d1d5b198a77deb9096e11b02aec7187221f384 (tag: Dev_V1.0)
Author: zhangsan <[email protected]>
Date: Sat Jul 10 10:59:09 2021 +0800
添加User文件夹
Users/Naura.Framework.Service.Users/Encryption.cs | 100 ++
Users/Naura.Framework.Service.Users/Group.cs | 215 ++++
Users/Naura.Framework.Service.Users/IUser.cs | 86 ++
.../IUserClientService.cs | 152 +++
.../Naura.Framework.Service.Users.csproj | 97 ++
.../Properties/AssemblyInfo.cs | 36 +
Users/Naura.Framework.Service.Users/User.cs | 266 +++++
Users/Naura.Framework.Service.Users/UserClient.cs | 16 +
.../UserClientService.cs | 901 +++++++++++++++
.../Naura.Framework.Service.Users/UserContract.cs | 207 ++++
Users/Naura.Framework.Service.Users/UserServer.cs | 1171 ++++++++++++++++++++
.../DesignTimeResolveAssemblyReferencesInput.cache | Bin 0 -> 6960 bytes
...ework.Service.Users.csproj.FileListAbsolute.txt | 6 +
...vice.Users.csprojResolveAssemblyReference.cache | Bin 0 -> 22983 bytes
.../obj/Debug/Naura.Framework.Service.Users.dll | Bin 0 -> 38912 bytes
commit 1c6e4116363e0dce9a931eeaad1d1dcd470bb673 (HEAD -> DevOps_RC3, tag: V0.3FixBug, origin/DevOps_V0.3FixBug, DevOps_V0.3FixBug)
Author: zhangsan <[email protected]>
Date: Sat Jul 10 14:07:01 2021 +0800
修复了V0.3FixBug
Readme.md | 1 +
1 file changed, 1 insertion(+)
commit 89d1d5b198a77deb9096e11b02aec7187221f384 (tag: Dev_V1.0)
Author: zhangsan <[email protected]>
Date: Sat Jul 10 10:59:09 2021 +0800
添加User文件夹
Users/Naura.Framework.Service.Users/Encryption.cs | 100 ++
Users/Naura.Framework.Service.Users/Group.cs | 215 ++++
Users/Naura.Framework.Service.Users/IUser.cs | 86 ++
.../IUserClientService.cs | 152 +++
.../Naura.Framework.Service.Users.csproj | 97 ++
.../Properties/AssemblyInfo.cs | 36 +
Users/Naura.Framework.Service.Users/User.cs | 266 +++++
Users/Naura.Framework.Service.Users/UserClient.cs | 16 +
.../UserClientService.cs | 901 +++++++++++++++
.../Naura.Framework.Service.Users/UserContract.cs | 207 ++++
Users/Naura.Framework.Service.Users/UserServer.cs | 1171 ++++++++++++++++++++
.../DesignTimeResolveAssemblyReferencesInput.cache | Bin 0 -> 6960 bytes
...ework.Service.Users.csproj.FileListAbsolute.txt | 6 +
...vice.Users.csprojResolveAssemblyReference.cache | Bin 0 -> 22983 bytes
.../obj/Debug/Naura.Framework.Service.Users.dll | Bin 0 -> 38912 bytes
.../obj/Debug/Naura.Framework.Service.Users.pdb | Bin 0 -> 77312 bytes
...tedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs | 0
...tedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs | 0
...tedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs | 0
.../GroupTests.cs | 51 +
.../Naura.Framework.Service.UsersTests.csproj | 99 ++
.../Properties/AssemblyInfo.cs | 36 +
.../DesignTimeResolveAssemblyReferencesInput.cache | Bin 0 -> 6571 bytes
....Service.UsersTests.csproj.FileListAbsolute.txt | 17 +
...UsersTests.csprojResolveAssemblyReference.cache | Bin 0 -> 38740 bytes
.../Debug/Naura.Framework.Service.UsersTests.dll | Bin 0 -> 5120 bytes
.../Debug/Naura.Framework.Service.UsersTests.pdb | Bin 0 -> 11776 bytes
...tedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs | 0
...tedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs | 0
...tedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs | 0
30 files changed, 3456 insertions(+)
commit b54962a30b090f02a39fc3c6185750cf07b068ea
Author: zhangsan <[email protected]>
Date: Sat Jul 10 10:58:30 2021 +0800
添加忽略文件
.gitignore | 1 +
1 file changed, 1 insertion(+)
commit e76012d77857841d344ac04893a158e75e8088fc
Author: zhangsan <[email protected]>
Date: Sat Jul 10 10:56:46 2021 +0800
添加Readme.md文件
Readme.md | 1 +
1 file changed, 1 insertion(+)
(END)
7.4显示某个文件的版本历史,包括文件改名
$ git log --follow [file]
$ git log --follow Readme.md
commit 1c6e4116363e0dce9a931eeaad1d1dcd470bb673 (HEAD -> DevOps_RC3, tag: V0.3FixBug, origin/DevOps_V0.3FixBug, DevOps_V0.3FixBug)
Author: zhangsan <[email protected]>
Date: Sat Jul 10 14:07:01 2021 +0800
修复了V0.3FixBug
commit e76012d77857841d344ac04893a158e75e8088fc
Author: zhangsan <[email protected]>
Date: Sat Jul 10 10:56:46 2021 +0800
添加Readme.md文件
$ git whatchanged [file]
$ git whatchanged Readme.md
commit 1c6e4116363e0dce9a931eeaad1d1dcd470bb673 (HEAD -> DevOps_RC3, tag: V0.3FixBug, origin/DevOps_V0.3FixBug, DevOps_V0.3FixBug)
Author: zhangsan <[email protected]>
Date: Sat Jul 10 14:07:01 2021 +0800
修复了V0.3FixBug
:100644 100644 6c1b17d 82f1ecb M Readme.md
commit e76012d77857841d344ac04893a158e75e8088fc
Author: zhangsan <[email protected]>
Date: Sat Jul 10 10:56:46 2021 +0800
添加Readme.md文件
:000000 100644 0000000 6c1b17d A Readme.md
7.5显示指定文件相关的每一次 diff
$ git log -p [file]
$ git log -p Readme.md
commit 1c6e4116363e0dce9a931eeaad1d1dcd470bb673 (HEAD -> DevOps_RC3, tag: V0.3FixBug, origin/DevOps_V0.3FixBug, DevOps_V0.3FixBug)
Author: zhangsan <[email protected]>
Date: Sat Jul 10 14:07:01 2021 +0800
修复了V0.3FixBug
diff --git a/Readme.md b/Readme.md
index 6c1b17d..82f1ecb 100644
--- a/Readme.md
+++ b/Readme.md
@@ -1 +1,2 @@
this is my first add
+修改了V0.3FixBug的Bug
commit e76012d77857841d344ac04893a158e75e8088fc
Author: zhangsan <[email protected]>
Date: Sat Jul 10 10:56:46 2021 +0800
添加Readme.md文件
diff --git a/Readme.md b/Readme.md
new file mode 100644
index 0000000..6c1b17d
--- /dev/null
+++ b/Readme.md
@@ -0,0 +1 @@
+this is my first add
7.6显示指定文件是什么人在什么时间修改过
$ git blame [file]
$ git blame Readme.md
7.7显示暂存区和上一个 commit 的差异
$ git diff --cached []
$ git diff --cached 89d1d5b198a77deb9096e11b02aec7187221f384
**不写commitID 默认是最新的commit ID **
7.8显示工作区与当前分支最新 commit 之间的差异
$ git diff HEAD
7.9显示两个分支之间的差异
$ git diff [first-branch]...[second-branch]$ git diff DevOps_RC3 DevOps_Dev
diff --git a/3.txt b/3.txt
new file mode 100644
index 0000000..13137df
--- /dev/null
+++ b/3.txt
@@ -0,0 +1 @@
+我想测试一下cherry-pick [commit]
diff --git a/Readme.md b/Readme.md
index 561f60a..8b12de6 100644
--- a/Readme.md
+++ b/Readme.md
@@ -1,3 +1,2 @@
this is my first add
-修改了V0.3FixBug的Bug
diff --git a/3.txt b/3.txt
new file mode 100644
index 0000000..13137df
--- /dev/null
+++ b/3.txt
@@ -0,0 +1 @@
+我想测试一下cherry-pick [commit]
diff --git a/Readme.md b/Readme.md
index 561f60a..8b12de6 100644
--- a/Readme.md
+++ b/Readme.md
@@ -1,3 +1,2 @@
this is my first add
-修改了V0.3FixBug的Bug
-测试一下git diff
+this is my first commit -a
diff --git a/ReleaseNotes.md b/ReleaseNotes.md
new file mode 100644
index 0000000..1a4e89a
--- /dev/null
+++ b/ReleaseNotes.md
@@ -0,0 +1,26 @@
+Version:(Dev_v1.0)
+
+Introduction:
+ welcome to use NCF package , using it , you can develop your personal control-application code quickly.
+
+ more information http://www.devops.com
+
+ this version is from V0.3FixBug
+
+
+System Requirements:
+ - CPU: 2C
+ - OS: windows7 64位
+ - Memory: 1G
+ - Hard-disk: 40G
+ - Others:
+Runtime Environment
+
+V0.3FixBug
+ - 修改Demo程序bug
+
+Dev_v1.0
+ - 建立DevOps平台项目
+ - 建立DevOps项目
+ - 需要.netframework4.6.1支持
+ - 需要mysqlV5.1.5支持
(END)
7.10显示两次commit之间的差异
$ git diff 304db4dfdd ab794ed848
7.11显示某次提交的元数据和内容变化
$ git show [commit]
$ git show ab794ed848f8cbe0f4b1be065555f5e0b1124d5d
7.12显示某次提交发生变化的文件
$ git show --name-only [commit]
$ git show --name-only b54962a30
7.13显示某次提交时,某个文件的内容
$ git show [commit]:[filename]
$ git show 304db4dfdd:Readme.md
显示所有的提交
$ git reflog
8.远程同步
8.1拉取远程仓库的所有变动
$ git fetch [remote]$ git fetch origin
8.2显示所有远程仓库
$ git remote -v
8.3显示某个远程仓库的信息
$ git remote show [remote]$ git remote show origin
warning: ----------------- SECURITY WARNING ----------------
warning: | TLS certificate verification has been disabled! |
warning: ---------------------------------------------------
warning: HTTPS connections may not be secure. See https://aka.ms/gcmcore-tlsverify for more information.
warning: ----------------- SECURITY WARNING ----------------
warning: | TLS certificate verification has been disabled! |
warning: ---------------------------------------------------
warning: HTTPS connections may not be secure. See https://aka.ms/gcmcore-tlsverify for more information.
* remote origin
Fetch URL: http://192.168.145.89/devops/devops.git
Push URL: http://192.168.145.89/devops/devops.git
HEAD branch: master
Remote branches:
DevOps_Dev tracked
DevOps_RC tracked
DevOps_RC1 tracked
DevOps_RC3 tracked
DevOps_Release tracked
DevOps_V0.3FixBug tracked
master tracked
Local branches configured for 'git pull':
DevOps_Dev merges with remote DevOps_Dev
DevOps_RC merges with remote DevOps_RC
DevOps_RC1 merges with remote DevOps_RC1
DevOps_RC2 merges with remote DevOps_RC1
DevOps_Release merges with remote DevOps_Release
DevOps_V0.3FixBug merges with remote DevOps_V0.3FixBug
master merges with remote master
Local refs configured for 'git push':
DevOps_Dev pushes to DevOps_Dev (up to date)
DevOps_RC pushes to DevOps_RC (up to date)
DevOps_RC1 pushes to DevOps_RC1 (up to date)
DevOps_RC3 pushes to DevOps_RC3 (fast-forwardable)
DevOps_Release pushes to DevOps_Release (up to date)
DevOps_V0.3FixBug pushes to DevOps_V0.3FixBug (up to date)
master pushes to master (up to date)
8.4增加一个新的远程仓库,并命名
$ git remote add [shortname] [url]
$ git remote add DevOps_MaTest http://192.168.145.89/devops/devops_matest.git
$ git remote -v
DevOps_MaTest http://192.168.145.89/devops/devops_matest.git (fetch)
DevOps_MaTest http://192.168.145.89/devops/devops_matest.git (push)
origin http://192.168.145.89/devops/devops.git (fetch)
origin http://192.168.145.89/devops/devops.git (push)
8.5取回远程仓库的变化,并与本地分支合并
$ git pull [remote] [branch]
8.6上传本地指定分支到远程仓库
$ git push [remote] [branch]
8.7强行推送当前分支到远程仓库,即使有冲突
$ git push [remote] --force
8.8推送所有分支到远程仓库
$ git push [remote] --all
9.撤销
9.1恢复暂存区的指定文件到工作区
$ git checkout [file]
9.2恢复某个 commit 的指定文件到工作区
$ git checkout [commit] [file]
9.3恢复上一个 commit 的所有文件到工作区
$ git checkout .
9.4重置暂存区的指定文件,与上一次 commit 保持一致,但工作区不变
$ git reset [file]
9.5重置暂存区与工作区,与上一次 commit 保持一致
$ git reset --hard
9.6重置当前分支的指针为指定 commit,同时重置暂存区,但工作区不变
$ git reset [commit]
9.7重置当前分支的 HEAD 为指定 commit,同时重置暂存区和工作区,与指定 commit 一致
$ git reset --hard [commit]
9.8重置当前 HEAD 为指定 commit,但保持暂存区和工作区不变
$ git reset --keep [commit]
9.9新建一个 commit,用来撤销指定 commit
9.10后者的所有变化都将被前者抵消,并且应用到当前分支
$ git revert [commit]
作者 | By小马哥
来源 | https://www.cnblogs.com/cndevops/p/14993331.html