https://git-scm.com/book/zh/v1/Git-%E5%B7%A5%E5%85%B7-%E9%87%8D%E5%86%99%E5%8E%86%E5%8F%B2
http://grunmin.github.io/2016/05/30/git%E4%BF%AE%E6%94%B9%E5%92%8C%E5%90%88%E5%B9%B6%E5%8E%86%E5%8F%B2%E6%8F%90%E4%BA%A4/
[root@hcdn-others-asyncTaskEntry-dev097-bjdx ffmpeg_monitor]# git log commit 702f156a9c5027fcb14f1a0e37c82abda1682b93 Author: baiwei <baiwei@qiyi.com> Date: Wed Sep 27 14:56:55 2017 +0800 python commit eba5dc72b7666b44daab5b7703ea4f4b9616c13d Author: baiwei <baiwei@qiyi.com> Date: Wed Sep 27 14:56:42 2017 +0800 js commit 2c919f4e101c3e6f0f4db45514ac6afdce4f97f2 Author: baiwei <baiwei@qiyi.com> Date: Tue Sep 26 16:29:58 2017 +0800 PGC声道模式默认为:音量标准化 commit d3d3ba844ebdbdff478acc6bcd185aa5e68fcf96 Author: baiwei <baiwei@qiyi.com> Date: Tue Sep 26 15:12:06 2017 +0800 视频帧率选项'是否跟信号保持一致'完善 commit 33de130901683128a1140c8f2f82f52469c6ed55 Author: baiwei <baiwei@qiyi.com> Date: Tue Sep 26 11:03:49 2017 +0800 uwsgi配置更新:多进程模式 update.sh脚本更新:完善备份机制
1 pick d3d3ba8 视频帧率选项'是否跟信号保持一致'完善
2 pick 2c919f4 PGC声道模式默认为:音量标准化
3 pick eba5dc7 js
4 pick 702f156 python
5
6 # Rebase 33de130..702f156 onto 33de130
7 #
8 # Commands:
9 # p, pick = use commit
10 # r, reword = use commit, but edit the commit message
11 # e, edit = use commit, but stop for amending
12 # s, squash = use commit, but meld into previous commit 所以需要你手动调整顺序,如果有需要的话
13 # f, fixup = like "squash", but discard this commit's log message
14 #
15 # If you remove a line here THAT COMMIT WILL BE LOST.
16 # However, if you remove everything, the rebase will be aborted.
17 #
##你可以任意的调整顺序,注意顺序的变化
1 pick d3d3ba8 视频帧率选项'是否跟信号保持一致'完善
2 fixup 702f156 python
3 reword 2c919f4 PGC声道模式默认为:音量标准化
4 fixup eba5dc7 js //把eba5dc7这个修改合并到上一个修改2c919f4中
5
6 # Rebase 33de130..702f156 onto 33de130
7 #
8 # Commands:
9 # p, pick = use commit
10 # r, reword = use commit, but edit the commit message
11 # e, edit = use commit, but stop for amending
12 # s, squash = use commit, but meld into previous commit
13 # f, fixup = like "squash", but discard this commit's log message
14 #
15 # If you remove a line here THAT COMMIT WILL BE LOST.
16 # However, if you remove everything, the rebase will be aborted.
17 #
[root@hcdn-others-asyncTaskEntry-dev097-bjdx ffmpeg_monitor]# git log commit 715e3c352a5d9d775fbfe9c165e4bfdcf8225c7f Author: baiwei <baiwei@qiyi.com> Date: Tue Sep 26 16:29:58 2017 +0800 PGC声道模式默认为:音量标准化 commit 8b64a648e2073f6a7f469f053e332d2e4e8cddb4 Author: baiwei <baiwei@qiyi.com> Date: Tue Sep 26 15:12:06 2017 +0800 视频帧率选项'是否跟信号保持一致'完善 commit 33de130901683128a1140c8f2f82f52469c6ed55 Author: baiwei <baiwei@qiyi.com> Date: Tue Sep 26 11:03:49 2017 +0800 uwsgi配置更新:多进程模式 update.sh脚本更新:完善备份机制 commit a9f4e581b3563a0141890c502b976f8949704b0a
git show commit_id 查看是否是你需要的结果
==============================================================
-
修改历史提交说明
git的rebase命令提供了对历史提交进行修改的功能。
-
git log
找到想要修改的commit的上一个commit的id -
git rebase -i [ID]
进入交互模式,此时可以看到形如
pick ed03fd1 test
pick f5c2a41 test
# Rebase fa0ab51..f5c2a41 onto fa0ab51 (2 command(s))
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out
最新的在最下面。
根据注释部分的说明,将第一行的pick
改为e
,然后:wq
退出,此时HEAD会返回到该提交处,执行git commit --amend "修改之后的message"
,再执行git rebase --continue
即可将该提交的message修改并返回到最新状态。
-
合并历史提交
合并历史提交与上个操作基本相同。调出上步中的交互界面后,将想要合并的commit的pick
改为s
,然后:wq
退出,此时后进入下一个交互界面,形如
# This is a combination of 2 commits.
这里显示了这两次commit的message,此时随你喜欢将两次message保留也好,自己重新写也好。同样:wq
保存,即可将两次提交合并。
因为最新提交在最下面,所以,该pick
为s
的提交会与上一提交合并,如果是连续修改pick
,则可以将多个提交合并起来。所以如果遇到这样的报错
1 |
Cannot 'squash' without a previous commit |
原因就是修改了第一行的pick
,因为之上是没有commit的,所以会报错。一旦遇到这个问题,执行
1 |
rm -fr "[REPO PATH]/.git/rebase-merge" |
后重新操作即可。
因此,执行git rebase
命令进行提交合并的时候,指定的commit的ID必须是本次合并相关的commit的上个commit,而不仅仅是被合并commit的上个commit。
如果你当前所在的分支跟上游分支的提交记录不一样的时候,单纯的git rebase -i不会弹出编辑框的,需要你输入完整的路径: git rebase -i upstream cur_branch
git rebase -i master PGC