如何使用 GIT 提取特定文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2517332/
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
How to pull a specific file with GIT?
提问by Paul Casal
Say you just want to get rid of the changes you've made to one file, and get back to whatever is in the repository. I used to do this in svn:
假设您只想删除对一个文件所做的更改,并返回到存储库中的任何内容。我曾经在 svn 中这样做:
rm a-file.txt
svn update a-file.txt
What is the equivalent in Git? I know how to fetch/pull evrythingfrom the repository, but how about one single file?
Git 中的等价物是什么?我知道如何获取/拉evrything从仓库中,但如何对一个单一的文件?
回答by Martin
To undo your (uncommitted) changes:
要撤消您的(未提交的)更改:
git checkout a-file.txt
If you have committed changes and want to undo them back to a certain previous commit:
如果您已提交更改并希望将它们撤消回某个先前的提交:
git checkout [some-older-commit-ref] a-file.txt
Btw, with Subversion you should have done:
顺便说一句,使用 Subversion 你应该这样做:
svn revert a-file.txt