1)回溯历史版本
git reset
$ git reset --hard 899bf3107f38542ea7a8cccc933abb3a420603b8
HEAD is now at 899bf31 Add index
$ git checkout -b fix-B
Switched to a new branch 'fix-B'
$ git add README.md
$ git commit -m "Fix B"
[fix-B 00a680c] Fix B
1 file changed, 3 insertions(+), 1 deletion(-)
$ git reflog
00a680c HEAD@{0}: commit: Fix B
899bf31 HEAD@{1}: checkout: moving from master to fix-B
899bf31 HEAD@{2}: reset: moving to 899bf3107f38542ea7a8cccc933abb3a420603
c86057c HEAD@{3}: merge feature-A: Merge made by the 'recursive' strategy
899bf31 HEAD@{4}: checkout: moving from feature-A to master
3bfe955 HEAD@{5}: checkout: moving from master to feature-A
899bf31 HEAD@{6}: checkout: moving from feature-A to master
3bfe955 HEAD@{7}: commit: Add feature-A
899bf31 HEAD@{8}: checkout: moving from master to feature-A
899bf31 HEAD@{9}: commit: Add index
3f9014e HEAD@{10}: commit (initial): First commit
$ git checkout master
Switched to branch 'master'
$ git reset --hard c86057c
HEAD is now at c86057c Merge branch 'feature-A'
2)消除冲突
$ git merge --no-ff fix-B
Auto-merging README.md
CONFLICT (content): Merge conflict in README.md
Automatic merge failed; fix conflicts and then commit the result.
$ git add README.md
$ git commit -m "Fix conflict"
[master 84f9afb] Fix conflict
3)修改提交信息
git commit --amend
$ git commit --amend
[master 9c2af5c] Merge branch 'fix-B'
$ git log --graph
* commit 9c2af5c9e92f9b86916286c83dc0974b7321fab7
|\ Merge: c86057c 00a680c
| | Author: Wu Jian <Jamsonwoo@126.com>
| | Date: Fri Feb 12 23:58:12 2016 +0800
| |
| | Fix conflict
| |
| * commit 00a680c343207893fff16c26dcbe09c51218f7b3
| | Author: Wu Jian <Jamsonwoo@126.com>
| | Date: Fri Feb 12 23:45:47 2016 +0800
| |
| | Fix B
| |
* | commit c86057c4c91d9ae4a841a9e80a1a971194103301
|\ \ Merge: 899bf31 3bfe955
| |/ Author: Wu Jian <Jamsonwoo@126.com>
|/| Date: Fri Feb 12 23:27:28 2016 +0800
| |
| | Merge branch 'feature-A'
| |
| * commit 3bfe9559a43f5dd199b0b9b0fac615aabfd7aa8d
|/ Author: Wu Jian <Jamsonwoo@126.com>
| Date: Fri Feb 12 23:13:24 2016 +0800
|
| Add feature-A
|
* commit 899bf3107f38542ea7a8cccc933abb3a420603b8
| Author: Wu Jian <Jamsonwoo@126.com>
| Date: Fri Feb 12 22:42:31 2016 +0800
|
| Add index
|
* commit 3f9014e2b31071d17f6d6d5ce144780a2e0dbf13
Author: Wu Jian <Jamsonwoo@126.com>
Date: Fri Feb 12 22:17:23 2016 +0800
First commit
4)压缩历史
git rebase -i
$ git checkout -b feature-C
Switched to a new branch 'feature-C'
$ git commit -am "Add feature-C"
[feature-C 3d7f663] Add feature-C
1 file changed, 1 insertions(+)
$ git diff
diff --git a/README.md b/README.md
index 48f518d..c194c43 100644
--- a/README.md
+++ b/README.md
@@ -2,4 +2,4 @@
- feature-A
- fix-B
- - faeture-C
\ No newline at end of file
+ - feature-C
\ No newline at end of file
$ git commit -am "Fix typo"
[feature-C 07475b3] Fix typo
1 file changed, 1 insertion(+), 1 deletion(-)
$ git rebase -i HEAD~2
编辑:pick 改为 fixup
[detached HEAD dbf98f4] Add feature-C
1 file changed, 2 insertions(+), 4 deletions(-)
Successfully rebased and updated refs/heads/feature-C.
$ git log --graph
* commit dbf98f40d2c86397774b42e282c13042f2c65559
| Author: Wu Jian <Jamsonwoo@126.com>
| Date: Sat Feb 13 00:16:11 2016 +0800
|
| Add feature-C
|
* commit 9c2af5c9e92f9b86916286c83dc0974b7321fab7
|\ Merge: c86057c 00a680c
| | Author: Wu Jian <Jamsonwoo@126.com>
| | Date: Fri Feb 12 23:58:12 2016 +0800
| |
| | Fix conflict
| |
......
$ git checkout master
Switched to branch 'master'
$ git merge --no-ff feature-C
Merge made by the 'recursive' strategy.
README.md | 1 +
1 file changed, 1 insertions(+)