合并后如何处理分支

本文翻译自:What to do with branch after merge

I had two branches: master and branch1 . 我有两个分支: masterbranch1 I just merged branch1 back into master and I'm done with that branch. 我刚刚将branch1合并回master然后完成了该分支。 Should I delete it or just let it sit around? 我应该删除它还是让它闲逛? Will deleting it cause any loss of data? 删除它会导致数据丢失吗?


#1楼

参考:https://stackoom.com/question/wlYs/合并后如何处理分支


#2楼

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. 另外,如果git认为您尚未完全合并它,它将警告您(并拒绝删除该分支)。 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 branch -D ),则您必须采取一些技巧来取回未合并的提交(请参见下文)。

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. git reflog显示最近签出的修订。 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中发生提交丢失的任何情况下, git fsck都是首选工具。


#3楼

I prefer RENAME rather than DELETE 我更喜欢重命名而不是删除

All my branches are named in the form of 我所有的分支都以

  • Fix/fix-<somedescription> or Fix/fix-<somedescription>
  • Ftr/ftr-<somedescription> or Ftr/ftr-<somedescription>
  • etc. 等等

Using Tower as my git front end, it neatly organizes all the Ftr/ , Fix/ , Test/ etc. into folders. 使用Tower作为我的git前端,它可以将所有Ftr/Fix/Test/等等整齐地组织到文件夹中。
Once I am done with a branch, I rename them to Done/...-<description> . 完成分支后, 重命名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.) 这样,它们仍然存在(可以方便地提供历史记录),并且我总是可以回去了解它的内容(功能,修复,测试等)。


#4楼

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值