基于SourceTree与命令号的Git优化操作;
修改最近一次的提交
这个场景对反复修改的bug很实用,有的时候打包提交了,然后可能因为环境变量,一些小颜色修改有要commit,这样Git提交记录会比较多。可以将最后一次修改合并到前一次。
命令行操作
//查看待提交文件
localhost:TC.Train.YPMinimalistMiniApps ljb48229$ git status
localhost:TC.Train.YPMinimalistMiniApps ljb48229$ git add util/api.js
localhost:TC.Train.YPMinimalistMiniApps ljb48229$ git commit --amend
[ljb 174205a] test3
Date: Tue Jun 26 14:31:37 2018 +0800
1 file changed, 1 insertion(+), 1 deletion(-)
//这个时候会打开上一次的文本编辑,保存退出即可。
SourceTree
image.png
需要修改一次特定的提交
需要修改以前的某一次提交
命令行
localhost:TC.Train.YPMinimalistMiniApps ljb48229$ git log
commit 174205a116f025f3cae22386406bf064abf02d52 (HEAD -> ljb)
Author: ljb48229 <ljb48229@ly.com>
Date: Tue Jun 26 14:31:37 2018 +0800
test3
commit 251782f5d7b56dcc077bf7b4b9c8ee6d42551113
Author: ljb48229 <ljb48229@ly.com>
Date: Tue Jun 26 14:19:36 2018 +0800
test2
commit 5287703b90952f1a8cbe2d19ac646a22b811d299
Author: ljb48229 <ljb48229@ly.com>
Date: Tue Jun 26 14:19:02 2018 +0800
Test1
commit a4e4af91eeafe94e00e5f1177087fcdada3a8c64
Author: ljb48229 <ljb48229@ly.com>
Date: Tue Jun 26 11:59:16 2018 +0800
test
//不管什么时候我们想要用 git rebase 命令修改一个特定的更改提交,我们首先要将我们分支的 HEAD 变基到我们想要修改的更改提交之前。
在这个场景中,我们需要修改test2的更改提交。
//这条命令会运行 Git 变基命令的交互模式,并且会打开文本编辑器展示你所变基到的更改提交之后的所有更改提交
localhost:TC.Train.YPMinimalistMiniApps ljb48229$ git rebase -I 5287703b90952f1a8cbe2d19ac646a22b811d299
pick 251782f test2
pick 174205a test3
# Rebase 5287703..174205a onto 5287703 (2 commands)
......省略
# Note that empty commits are commented out
然后修改为 edit 251782f test2,保存退出
localhost:TC.Train.YPMinimalistMiniApps ljb48229$ git rebase -I 5287703b90952f1a8cbe2d19ac646a22b811d299
Stopped at 251782f... test2
You can amend the commit now, with
git commit --amend
Once you are satisfied with your changes, run
git rebase --continue
//接下修改你要修改的东西,然后git add ....
//再 git rebase --continue
SourceTree
屏幕快照 2018-06-26 下午3.04.17.png
image.png
image.png
现在是这个样子.png
屏幕快照 2018-06-26 下午3.08.25.png
image.png
添加、移除或者合并提交
localhost:TC.Train.YPMinimalistMiniApps ljb48229$ git log
commit 1d2d763dff9761baa088d368ac2f3e8b5f6f6116 (HEAD -> ljb)
Author: ljb48229 <ljb48229@ly.com>
Date: Tue Jun 26 14:31:37 2018 +0800
test3
commit a917f37ae6a9bf8fe548a44b8c54a96b401dbb31
Author: ljb48229 <ljb48229@ly.com>
Date: Tue Jun 26 15:12:20 2018 +0800
rebase冲突解决
commit 1b758831418aa0dbe1ecc6713c86cceed1543cc2
Author: ljb48229 <ljb48229@ly.com>
Date: Tue Jun 26 15:10:52 2018 +0800
test2-rebase
commit b000438d8ce54b7572d907943cc43e7930a44b0f
Author: ljb48229 <ljb48229@ly.com>
Date: Tue Jun 26 15:13:58 2018 +0800
Test1-rebase
commit 8d69e822948ac3ee25f7300451eaf784a227fb69
Author: ljb48229 <ljb48229@ly.com>
Date: Tue Jun 26 15:15:05 2018 +0800
Test1
commit 5287703b90952f1a8cbe2d19ac646a22b811d299
Author: ljb48229 <ljb48229@ly.com>
Date: Tue Jun 26 14:19:02 2018 +0800
Test1
commit a4e4af91eeafe94e00e5f1177087fcdada3a8c64
Author: ljb48229 <ljb48229@ly.com>
Date: Tue Jun 26 11:59:16 2018 +0800
test
我要合并rebase冲突解决
,test2-rebase
,Test1-rebase
,Test1
到test3
- 把你想要合并的那些更改提交往上移动,以使得它们位于最终合并的更改提交之下。
- 将每一个更改提交的模式由 pick 改为 squash 或者 fixup。
注:squash 模式会在描述中保留修改时的信息。而fixup 不会,它只会保留原来的提交信息。
localhost:TC.Train.YPMinimalistMiniApps ljb48229$ git rebase -I a4e4af91eeafe94e00e5f1177087fcdada3a8c64
Successfully rebased and updated refs/heads/ljb.
//修改为
pick 5287703 Test1
fixup 8d69e82 Test1
fixup b000438 Test1-rebase
fixup e0aa572 test2-rebase
pick a7513b7 test3
localhost:TC.Train.YPMinimalistMiniApps ljb48229$ git log
commit 4db6fae3027b73820773d581142010c848b740b9 (HEAD -> ljb)
Author: ljb48229 <ljb48229@ly.com>
Date: Tue Jun 26 14:31:37 2018 +0800
test3
commit c1a773da8cc4b84102dc2ec8dc9511f05d53ff59
Author: ljb48229 <ljb48229@ly.com>
Date: Tue Jun 26 14:19:02 2018 +0800
Test1
commit a4e4af91eeafe94e00e5f1177087fcdada3a8c64
Author: ljb48229 <ljb48229@ly.com>
Date: Tue Jun 26 11:59:16 2018 +0800
test
SourceTree
image.png
image.png
image.png
网友评论