检出以前提交的文件并将其修改为HEAD

检出以前提交的文件并将其修改为HEAD

本文介绍了Git:检出以前提交的文件并将其修改为HEAD的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近将一个文件提交给我的分支的HEAD,它有错误。我需要做以下事情:


  • 从HEAD之前的一个提交中获取该文件


  • 将该文件重新提交到HEAD中




执行该操作的最佳方式是什么?

解决方案

您几乎已经自己说过了: 一次提交:

  $> git checkout HEAD〜1 path / to / file.ext 

然后提交它:

  $> git commit -a -m'从旧版本检索的文件'

如果仅对该文件所做的更改目前在上次提交中,您甚至可以使用 git-revert

  $> git revert HEAD 

我认为将它作为一个单独的提交会更好,因为它会准确地告诉您你已经回复了什么,为什么。然而,你可以通过使用 - 修改开关到 git-commit 来压缩这个到之前的提交中。


I recently committed a file to the HEAD of my branch which has errors in it. I need to do the following things:

  • Get that file from one commit previous to HEAD

  • Commit that file back into HEAD

What's the best way of going about that?

解决方案

You've practically said it yourself:

First get the file back from one commit before:

$> git checkout HEAD~1 path/to/file.ext

Then commit it:

$> git commit -a -m 'Retrieved file from older revision'

If only the changes to that file where present in the last commit, you can even use git-revert:

$> git revert HEAD

I think it would be better to make this a separate commit, because it tells you exactly what you've reverted, and why. However, you can squash this into the previous commit by using the --amend switch to git-commit.

这篇关于Git:检出以前提交的文件并将其修改为HEAD的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 20:22