合并后如何处理分支 [英] What to do with branch after merge

查看:153
本文介绍了合并后如何处理分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个分支: master branch1 。我只是将 branch1 合并到 master 中,并且完成了该分支。我应该删除它还是让它坐下来?删除它会导致数据丢失吗?

解决方案

合并后,删除分支是安全的:

  git branch -d branch1 

另外,如果git认为你没有完全合并它,它会警告你(并拒绝删除分支)。如果你强制删除一个尚未完全合并的分支(带有 git branch -D ),你必须做一些技巧才能获得未提交的提交(见下文) 。



虽然有一些原因可以保持分支。例如,如果它是一个功能分支,您可能希望能够对该分支中仍然存在的功能进行修正。



如果您还想删除分支一个远程主机,你可以这样做:

  git push origin:branch1 
pre>

这将强制删除远程分支(这不会影响已检出的资源,但不会阻止任何具有推入访问权限的人重新推/创建它)。






git reflog 显示最近检出修订。您在最近版本库历史记录中签出的任何分支也会显示在那里。除此之外,在任何git失败的情况下, git fsck 都将成为首选工具。


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?

解决方案

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).

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.

这篇关于合并后如何处理分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆