Git:如何在忽略所有本地更改的情况下签出分支?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9586362/
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
Git: How do I checkout a branch ignoring all local changes?
提问by ScottCate
After I have messed around with directories (created/removed) and added/edited both text and binary files, how do I tell git to throw away all my changes, and bring the branch down again, as if I never messed with anything?
在我弄乱了目录(创建/删除)并添加/编辑了文本和二进制文件之后,我如何告诉 git 丢弃我的所有更改,并再次关闭分支,就好像我从来没有弄乱过任何东西一样?
Currently I'm doing these two commands.
目前我正在执行这两个命令。
git stash
git stash clear
git pull <remote> <branch>
which seems to work. I read in help that -f is used to throw away local changes. If that's the case does ...
这似乎有效。我在帮助中读到 -f 用于丢弃本地更改。如果是这样的话...
git checkout <branch> -f
do the same thing?
做同样的事?
Thank you!
谢谢!
回答by KingCrunch
回答by Tom
git reset --hard
If you want a visual representation of the Branches and commits first type
如果您想要分支的可视化表示并提交第一种类型
gitk
Right-click on the desired previous commit and click on "Reset branch to here" You will be presented with 3 options
右键单击所需的先前提交,然后单击“将分支重置到此处”您将看到 3 个选项
Use HARD : to discard all the local changes
使用 HARD :丢弃所有本地更改
OR
或者
Use MIXED: to keep the local changed incase if you want to commit again, and it resets the index to the previous commit
如果您想再次提交,请使用 MIXED: 保持本地更改,并将索引重置为上一次提交