Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修改 git 历史提交 commit 信息【重写历史】 #16

Open
licoded opened this issue Jul 31, 2021 · 0 comments
Open

修改 git 历史提交 commit 信息【重写历史】 #16

licoded opened this issue Jul 31, 2021 · 0 comments
Labels
Milestone

Comments

@licoded
Copy link
Owner

licoded commented Jul 31, 2021

执行 git 命令, 修改近三次的信息

git rebase -i HEAD~3

将会得到如下的信息,这里的提交日志是和 git log 倒顺序排列的,我们要修改的日志信息位于第一位.

  1 pick 2275781 init test configuration
  2 pick 223fc80 unit test case
  3 pick 9ac1179 update test case
  4
  5 # Rebase 79db0bd..9ac1179 onto 79db0bd (3 commands)
  6 #
  7 # Commands:
  8 # p, pick = use commit
  9 # r, reword = use commit, but edit the commit message
 10 # e, edit = use commit, but stop for amending
 11 # s, squash = use commit, but meld into previous commit
 12 # f, fixup = like "squash", but discard this commit's log message
 13 # x, exec = run command (the rest of the line) using shell
 14 # d, drop = remove commit
 15 #
 16 # These lines can be re-ordered; they are executed from top to bottom.
 17 #
 18 # If you remove a line here THAT COMMIT WILL BE LOST.
 19 #
 20 # However, if you remove everything, the rebase will be aborted.
 21 #
 22 # Note that empty commits are commented out

我们现在要修改修改要 init test configuration 这条日志,那么修改的日志为,将第一个 pick 修改为 edit, 然后
:wq 退出

  1 edit 2275781 should find method from parent
  2 pick 223fc80 unit test case
  3 pick 9ac1179 update test case

将会看到如下信息

client_java git:(fix_aop_no_class_defined) git rebase -i HEAD~3
Stopped at 2275781...  should find method from parent
You can amend the commit now, with

  git commit --amend

Once you are satisfied with your changes, run

  git rebase --continue
➜  client_java git:(2275781)

意思就是如果要改日志,执行 git commit --amend,如果修改完成后,执行 git rebase --continue
完事儿之后再运行 git log 就会看到修改以后的注释信息了

参考链接

注意

提交内容之间有冲突的话,慎用!!!【解决冲突后会把冲突的两次提交合并为一次提交】

@licoded licoded added this to the 随手记录 milestone Jul 31, 2021
@licoded licoded added the git label Jul 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant