如何修改git中的指定提交? [英] How to modify a specified commit in git?

查看:285
本文介绍了如何修改git中的指定提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通常会提交一个提交列表供审查。如果我有:

  • HEAD

  • Commit3

  • Commit2

  • Commit1



我知道我可以用 git commit --amend 来修改头部提交,但是如何修改 Commit1 ,因为它不是 HEAD 提交?

解决方案

例如,您可以使用git rebase修改回提交 bbc643cd ,运行

  $ git rebase --interactive'bbc643cd ^'
选择
编辑<$ c $ <>
$ b> / code>在你要修改的提交行中。进行更改,然后使用与之前相同的消息提交它们:

  $ git commit --all --amend  - no-edit 

修改提交,之后

  $ git rebase --continue 

返回到前一个头提交。



警告:请注意,这将更改提交的SHA-1,所有的孩子 - 换句话说,这从这一点重写了历史。 如果您使用命令> git push --force


I usually submit a list of commits for review. If I have:

  • HEAD
  • Commit3
  • Commit2
  • Commit1

I know that I can modify head commit with git commit --amend, but how can I modify Commit1, given that it is not the HEAD commit?

解决方案

You can use git rebase, for example, if you want to modify back to commit bbc643cd, run

$ git rebase --interactive 'bbc643cd^'

In the default editor, modify pick to edit in the line whose commit you want to modify. Make your changes and then commit them with the same message you had before:

$ git commit --all --amend --no-edit

to modify the commit, and after that

$ git rebase --continue

to return back to the previous head commit.

WARNING: Note that this will change the SHA-1 of that commit as well as all children -- in other words, this rewrites the history from that point forward. You can break repos doing this if you push using the command git push --force

这篇关于如何修改git中的指定提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆