Git 将功能分支中的单个文件重置为与 master 中的相同

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37972753/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 04:17:27  来源:igfitidea点击:

Git reset single file in feature branch to be the same as in master

git

提问by Anton Belev

I'm trying to revert my changes in a single filein my feature branch and I want this file to be the same as in master.

我试图在我的功能分支中的单个文件中恢复我的更改,我希望这个文件与 master 中的相同。

I tried:

我试过:

git checkout -- filename
git checkout filename 
git checkout HEAD -- filename

It seems that none of these made any changes to my feature branch. Any suggestions?

似乎这些都没有对我的功能分支进行任何更改。有什么建议?

回答by Dennan Hogue

If you want to revert the file to its state in master:

如果要将文件恢复到其状态master

git checkout origin/master [filename]

git checkout origin/master [filename]

回答by Chris Maes

you are almost there; you just need to give the reference to master; since you want to get the file from the master branch:

你快到了;你只需要给master参考;因为你想从 master 分支获取文件:

git checkout master -- filename

Note that the differences will be cached; so if you want to see the differences you obtained; use

请注意,差异将被缓存;所以如果你想看看你得到的差异;用

git diff --cached