再次使 git 分支等于 master
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13489725/
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
Make a git branch equal to master again
提问by Confusion
Short version
精简版
What is the easiest way to make a branch equal to master
again, discarding any differences?
Up until now, I simply used git branch -D wip
, followed by git checkout -b wip
, but that seems a bit silly.
使分支master
再次等于并丢弃任何差异的最简单方法是什么?到现在为止,我只是简单地使用了git branch -D wip
,其次是git checkout -b wip
,但这似乎有点傻。
Motivation
动机
I often have a wip
branch alongside my master
branch, for 'work in progress'. Sometimes the work on such a branch gets 'left behind' and when I rediscover it, I find I no longer want it. This rediscovery often happens when I want to use the branch to store a new set of 'work in progress' and I find I simply want to discard any differences with master
, so the new 'work in progress' fits on top. Figuring out the differences is not worth the trouble: the solution described above works fine for me. Any better solutions to address this use case?
我经常wip
在我的分支旁边有一个分支master
,用于“正在进行的工作”。有时在这样一个分支上的工作被“抛在后面”,当我重新发现它时,我发现我不再想要它了。当我想使用分支来存储一组新的“进行中的工作”并且我发现我只想丢弃与 的任何差异时master
,经常会发生这种重新发现,因此新的“进行中的工作”适合放在最前面。找出差异不值得麻烦:上述解决方案对我来说很好用。有没有更好的解决方案来解决这个用例?
采纳答案by qqx
If you really want to blow away the previous branch with that name, and create a new one you could just use:
如果你真的想用那个名字吹走上一个分支,并创建一个新的分支,你可以使用:
git checkout -B wip master
Using the capital version rather than -b
will cause git to switch to the named branch, and reset it to the new starting point named as the last argument. If you're currently at the desired starting point you could leave off the last argument (master
here), it will default to using HEAD
.
使用大写版本而不是-b
将导致 git 切换到命名分支,并将其重置为名为最后一个参数的新起点。如果您当前处于所需的起点,则可以省略最后一个参数(master
此处),它将默认使用HEAD
.
回答by Intrepidd
try this one in your branch :
在你的分支试试这个:
git reset --hard master
This will make your branch identical to master, remove all commits you may have done, and discard all the files in the staging area.
这将使您的分支与 master 相同,删除您可能已完成的所有提交,并丢弃暂存区中的所有文件。