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