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

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

问题描述

我通常会提交一份提交清单供审核.如果我有以下提交:

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

  1. HEAD
  2. Commit3
  3. Commit2
  4. Commit1
  1. HEAD
  2. Commit3
  3. Commit2
  4. Commit1

...我知道我可以使用git commit --amend修改head commit.但是,鉴于它不是HEAD提交,我该如何修改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 commit bbc643cd, run

$ git rebase --interactive 'bbc643cd^'

请注意命令末尾的插入符^,因为实际上您需要在执行之前重新变回到 您要修改的.

Please note the caret ^ at the end of the command, because you need actually to rebase back to the commit before the one you wish to modify.

在默认编辑器中,在提及"bbc643cd"的行中将pick修改为edit.

In the default editor, modify pick to edit in the line mentioning 'bbc643cd'.

保存文件并退出:git将解释并自动执行文件中的命令.您会发现自己处在刚刚创建了提交bbc643cd的先前情况中.

Save the file and exit: git will interpret and automatically execute the commands in the file. You will find yourself in the previous situation in which you just had created commit bbc643cd.

此时,bbc643cd是您的最后一次提交,您可以

At this point, bbc643cd is your last commit and you can easily amend it: make your changes and then commit them with the command:

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

然后输入:

$ git rebase --continue

返回到先前的HEAD提交.

to return back to the previous HEAD commit.

警告:请注意,这将更改该提交以及所有子项的SHA-1 -换句话说,这将从该点开始重写历史记录. 如果您使用命令git push --force

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

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

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