git 合并后如何处理分支
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14005854/
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
What to do with branch after merge
提问by Alison
I had two branches: master
and branch1
. I just merged branch1
back into master
and I'm done with that branch. Should I delete it or just let it sit around? Will deleting it cause any loss of data?
我有两个分支:master
和branch1
。我刚刚合并branch1
回master
,我已经完成了那个分支。我应该删除它还是让它闲着?删除它会导致数据丢失吗?
回答by Jonas Sch?fer
After the merge, it's safe to delete the branch:
合并后,删除分支是安全的:
git branch -d branch1
Additionally, git will warn you (and refuse to delete the branch) if it thinks you didn't fully merge it yet. If you forcefully delete a branch (with git branch -D
) which is not completely merged yet, you have to do some tricks to get the unmerged commits back though (see below).
此外,如果 git 认为您尚未完全合并它,它会警告您(并拒绝删除该分支)。如果你强行删除一个git branch -D
还没有完全合并的分支(with ),你必须做一些技巧来恢复未合并的提交(见下文)。
There are some reasons to keep a branch around though. For example, if it's a feature branch, you may want to be able to do bugfixes on that feature still inside that branch.
不过,有一些理由可以保留一个分支。例如,如果它是一个功能分支,您可能希望能够对仍在该分支内的该功能进行错误修复。
If you also want to delete the branch on a remote host, you can do:
如果您还想删除远程主机上的分支,您可以执行以下操作:
git push origin :branch1
This will forcefully delete the branch on the remote (this will not affect already checked-out repositiories though and won't prevent anyone with push access to re-push/create it).
这将强制删除远程上的分支(但这不会影响已经签出的存储库,并且不会阻止任何具有推送访问权限的人重新推送/创建它)。
git reflog
shows the recently checked out revisions. Any branch you've had checked out in the recent repository history will also show up there. Aside from that, git fsck
will be the tool of choice at any case of commit-loss in git.
git reflog
显示最近签出的修订。您在最近的存储库历史记录中签出的任何分支也将显示在那里。除此之外,git fsck
在任何 git 提交丢失的情况下,都将成为首选工具。
回答by Yohst
I prefer RENAMErather than DELETE
我更喜欢重命名而不是删除
All my branches are named in the form of
我所有的分支都以以下形式命名
Fix/fix-<somedescription>
orFtr/ftr-<somedescription>
or- etc.
Fix/fix-<somedescription>
或者Ftr/ftr-<somedescription>
或者- 等等。
Using Tower as my git front end, it neatly organizes all the Ftr/
, Fix/
, Test/
etc. into folders.
Once I am done with a branch, I renamethem to Done/...-<description>
.
使用塔作为我的git的前端,它巧妙地组织所有的Ftr/
,Fix/
,Test/
等到文件夹中。
完成分支后,我将它们重命名为Done/...-<description>
.
That way they are still there (which can be handy to provide history) and I can always go back knowing what it was (feature, fix, test, etc.)
这样他们仍然在那里(这可以方便地提供历史记录),我可以随时回去知道它是什么(功能,修复,测试等)
回答by ahmednabil88
If you will go ahead and DELETE the branch after merge it.
Just take care of
All hyperlinks URLs references of your DELETED branches, will be BROKEN.
如果您将继续并在合并后删除分支。
只需注意
您的 DELETED 分支的所有超链接 URL 引用,将被BROKEN。