您当前的位置: 首页 > 学无止境 > 心得笔记 网站首页心得笔记
16 怎么修改老旧commit的mess...
发布时间:2020-07-12 13:34:49编辑:雪饮阅读()
之前有讲怎样最新提交的commit的备注,这次主要是指定某个commit的备注的修改。
如下,这里有3个commit,这里要修改中间的这个commit的日志
xy@DESKTOP-BG9HNHK MINGW64 ~/Desktop/web/web (branch2)
$ git log
commit ac86aaf5d9dca4b0bacda1c19dae2e8951d412e8 (HEAD -> branch2)
Author: xy220807 <1509272975@qq.com>
Date: Sun Jul 5 15:46:38 2020 +0800
branch2dir3
commit 795e4fcb73551a8f172af6e421d136da3738b133
Author: xy220807 <1509272975@qq.com>
Date: Sun Jul 5 15:34:12 2020 +0800
branch2 commit 20200705
commit 48142d39abcd7f51c16d4eb50127445af496d056 (temp, master)
Author: 雪饮 <1509272975@qq.com>
Date: Sat Jul 4 11:27:29 2020 +0800
modified index.html
要修改某个指定commit的日志,则需要通过变基指定其上一条id进行修改,则这里上一条commit的id就是第三个的id,则有
xy@DESKTOP-BG9HNHK MINGW64 ~/Desktop/web/web (branch2)
$ git rebase -i 48142d39abcd7f51c16d4eb50127445af496d056
然后出现一个vi的交互编辑如
pick 795e4fc branch2 commit 20200705
pick ac86aaf branch2dir3
# Rebase 48142d3..ac86aaf onto 48142d3 (2 commands)
#
# Commands:
# p, pick <commit> = use commit
# r, reword <commit> = use commit, but edit the commit message
# e, edit <commit> = use commit, but stop for amending
# s, squash <commit> = use commit, but meld into previous commit
# f, fixup <commit> = like "squash", but discard this commit's log message
# x, exec <command> = run command (the rest of the line) using shell
# b, break = stop here (continue rebase later with 'git rebase --continue')
# d, drop <commit> = remove commit
# l, label <label> = label current HEAD with a name
# t, reset <label> = reset HEAD to a label
# m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]
# . create a merge commit using the original merge commit's
# . message (or the oneline, if no original merge commit was
# . specified). Use -c <commit> to reword the commit message.
#
# These lines can be re-ordered; they are executed from top to bottom.
参考该交互编辑中的提示内容,则我们只需要将这里第一行的命令改为r即可,因为我们只改备注
r 795e4fc branch2 commit 20200705
pick ac86aaf branch2dir3
# Rebase 48142d3..ac86aaf onto 48142d3 (2 commands)
#
# Commands:
# p, pick <commit> = use commit
# r, reword <commit> = use commit, but edit the commit message
# e, edit <commit> = use commit, but stop for amending
# s, squash <commit> = use commit, but meld into previous commit
# f, fixup <commit> = like "squash", but discard this commit's log message
# x, exec <command> = run command (the rest of the line) using shell
# b, break = stop here (continue rebase later with 'git rebase --continue')
# d, drop <commit> = remove commit
# l, label <label> = label current HEAD with a name
# t, reset <label> = reset HEAD to a label
# m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]
# . create a merge commit using the original merge commit's
# . message (or the oneline, if no original merge commit was
# . specified). Use -c <commit> to reword the commit message.
#
# These lines can be re-ordered; they are executed from top to bottom.
然后我们保存退出就会出现第二个vi交互,如
这里我们直接修改第一行内容即可,这里的第一行就是我们之前的备注。
然后最后保存就会提示如
xy@DESKTOP-BG9HNHK MINGW64 ~/Desktop/web/web (branch2)
$ git rebase -i 48142d39abcd7f51c16d4eb50127445af496d056
[detached HEAD 24df95a] branch2 commit 20200712
Date: Sun Jul 5 15:34:12 2020 +0800
2 files changed, 2 insertions(+)
create mode 100644 branch2dir1/1.txt
create mode 100644 branch2dir1/dir1/2.txt
Successfully rebased and updated refs/heads/branch2.
根据这里的提示,可知
变基原理:产生分离头指针并修改相关内容重新产生一个最新的commit
然后我们查看log日志,发现中间那条commit的确被修改了备注,但是其id也和之前不一样了
xy@DESKTOP-BG9HNHK MINGW64 ~/Desktop/web/web (branch2)
$ git log -n3
commit bfb75cfc06a3b473b0a19c793d456e8c6fc59eac (HEAD -> branch2)
Author: xy220807 <1509272975@qq.com>
Date: Sun Jul 5 15:46:38 2020 +0800
branch2dir3
commit 24df95ae5a25430a2092a992bbcf34b19cb3bc7b
Author: xy220807 <1509272975@qq.com>
Date: Sun Jul 5 15:34:12 2020 +0800
branch2 commit 20200712
commit 48142d39abcd7f51c16d4eb50127445af496d056 (temp, master)
Author: 雪饮 <1509272975@qq.com>
Date: Sat Jul 4 11:27:29 2020 +0800
modified index.html
这里的变基是对在自己的分支还没有集成到团队分支之前的变基,如果已经集成到团队的就不要轻易变基了,会影响到团队的其他人的哈。
关键字词:commit,message,指定commit,备注修改,备注