Which branch do commits from a deleted branch belong to?

我的未来我决定 提交于 2019-11-28 08:40:40

问题


If I merge branch A into branch B and then delete A, which branch do commits from branch A (now deleted) belong to?


回答1:


Git branches are mere pointers to commits. Asking

Which branch does this commit belong to?

doesn't really make sense (at least, not in the general case) because commits may very well be reachable from multiple branches (or even from none at all!).

Consider the following example:

Commit F is currently only reachable from the bugfix branch; at this point, it makes sense to say that commit F "belongs" to the bugfix branch. However, if you then merge bugfix into master, by running

git checkout master
git merge bugfix

then commit F becomes reachable from both of those branches:

Commit F can no longer be said to belong to bugfix more than to master. If you then delete bugfix, commit F will again be reachable from only one branch, master this time, in which case it will make sense to say that commit F "belongs" to master.


In summary, a commit cannot, in general, be thought of as exclusively belonging to any one branch. However, a question that always does make sense is

From which branches (if any) is this commit reachable?



来源:https://stackoverflow.com/questions/29257491/which-branch-do-commits-from-a-deleted-branch-belong-to

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!