修改过去在git中提交的单个文件 [英] amending a single file in a past commit in git

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

问题描述

我想在过去的提交中修复一个文件。这可能会影响所有的提交提交。



有没有简单的方法来做到这一点?你能给我一个如何做的指导吗?

很多时候,当我犯了两次错误,我发现我在第一次提交时出错了,我希望修复这个错误,而不必'git reset'我的最后一个好提交。



澄清。我想更改实际的提交,即我希望更改过去提交的内容。 IOW我想更改历史记录!

解决方案

如果您只想修改第二个到最后一个提交(例如,不久前,特别是在许多分支和合并之前),那么我使用这个过程:


  1. git checkout -b tmp bad-commit

  2. 修复文件

  3. git commit - 修改

  4. git rebase tmp master

如果你在两者之间进行了合并,你可以尝试 rebase -i -p ,但结果可能会有所不同。


I want to fix a file in past commit. This might affect all ascending commits.

Is there an easy way to do that? Can you give me a guideline of how to do that?

Many times when I commit twice I find that I've had error in the first commit, and I wish to fix the error without having to 'git reset' my last good commit.

For clarification. I want to change the actual commit, that is, I want the content of the past commit to be changed. IOW I want to change history!

解决方案

If you only want to amend the second to last commit (eg. not long ago, especially not before many branches and merges), then I use this procedure:

  1. git checkout -b tmp bad-commit
  2. fix the files
  3. git commit --amend
  4. git rebase tmp master

If you have merges in between, you may wanna try rebase -i -p, but the results may vary.

这篇关于修改过去在git中提交的单个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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