git 用原始存储库中的内容强制覆盖本地文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3949804/
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
Force overwrite of local file with what's in origin repo?
提问by Blankman
I want to get the latest file that's in the repository, and overwrite what I have locally. How can I do this with the git client?
我想获取存储库中的最新文件,并覆盖我在本地拥有的文件。我怎样才能用 git 客户端做到这一点?
回答by Amber
If you want to overwrite only one file:
如果只想覆盖一个文件:
git fetch
git checkout origin/master <filepath>
If you want to overwrite allchanged files:
如果要覆盖所有更改的文件:
git fetch
git reset --hard origin/master
(This assumes that you're working on master
locally and you want the changes on the origin's master
- if you're on a branch, substitute that in instead.)
(这假设您在master
本地工作,并且您希望对原点进行更改master
- 如果您在分支上,请将其替换。)
回答by J.M. Janzen
Simplest version, assuming you're working on the same branch that the file you want is on:
最简单的版本,假设你在你想要的文件所在的同一个分支上工作:
git checkout path/to/file
.
git checkout path/to/file
.
I do this so often that I've got an alias set to gc='git checkout'
.
我经常这样做,以至于我将别名设置为gc='git checkout'
.
回答by arn-arn
This worked for me:
这对我有用:
git reset HEAD <filename>
回答by Chand Priyankara
Full sync has few tasks:
完全同步有几个任务:
- reverting changes
- removing new files
- get latest from remote repository
- 还原更改
- 删除新文件
- 从远程存储库获取最新信息
git reset HEAD --hard
git clean -f
git pull origin master
git reset HEAD --hard
git 清理 -f
git pull 原点大师
Or else, what I prefer is that, I may create a new branch with the latest from the remote using:
或者,我更喜欢的是,我可以使用以下命令从远程创建一个新分支:
git checkout origin/master -b <new branch name>
origin is my remote repository reference, and master is my considered branch name. These may different from yours.
origin 是我的远程存储库引用,master 是我考虑的分支名称。这些可能与您的不同。