简体   繁体   English

我可以安全地删除已合并到master的Git主题分支吗?

[英]Can I safely remove my Git topic branch that has been merged into master?

如果我创建并推送了很久以前已合并到master的主题分支,是否可以安全地运行git push origin :foobranch而不必担心它会以某种方式删除合并到master或其他分支的数据?

As long as there are no outstanding commits, its safe. 只要没有未完成的提交,它都是安全的。 If you want to be sure 如果您想确定

git checkout master
git merge foobranch

This should result in a fast-forward merge (that does not affect the history). 这将导致快速合并(不影响历史记录)。 If not, maybe there were unmerged commits. 如果没有,也许有未合并的提交。 However, now you are completely safe 但是,现在您完全安全了

git branch -d foobranch
git push origin :foobranch

Yes, you can safely delete a branch that has been merged into another branch. 是的,您可以安全地删除已合并到另一个分支的分支。 Branches are like movable pointers into the commit graph, and if you delete a branch, it's just removing that pointer. 分支就像提交图中的可移动指针,如果删除分支,则只是删除该指针。 The commit graph remains, and in your case the master branch will still contain the history of the branch you've removed. 提交图仍然存在,在您的情况下, master分支仍将包含已删除分支的历史记录。

It is perfectly safe. 这是绝对安全的。

Any commit is linked to a tree (ie, your project files), and potentially, several commits point to the same tree. 任何提交都链接到一棵树(即,您的项目文件),并且可能有多个提交指向同一棵树。 It is only when no commit links to a tree anymore that it may be garbage collected. 只有当不再有提交链接链接到树时,它才可能被垃圾回收。

If you still need to recollect it somehow and don't even have a local ref to the commit, there is the reflog, which is cleaned up only after 90 days (I think ) by default. 如果您仍然需要以某种方式重新收集它,甚至没有提交的本地引用,则有一个reflog,默认情况下,该日志仅在90天(我认为 )之后才被清除。

删除提交或分支不会影响其他分支上的其他提交,即使该提交是在分支之间共享的,或者该分支已合并到其他分支中也是如此。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Git:如何删除已经提交,推送并合并到master的分支? - Git: How do I remove a branch that has already been committed, pushed, and merged into master? 我如何知道一个分支是否已经合并到 master 中? - How can I know if a branch has been already merged into master? 分支合并到 master 后的 git rebase - git rebase after branch has been merged into master SQUASHED时检查Git分支是否已合并为主分支? - Checking if a Git branch has been merged into master when SQUASHED? 功能分支合并到master后,我会继续做什么呢? - What shall I do after my feature branch has been merged into master but I have continued to work on it? 如何验证git项目的release分支的修补程序已全部合并到master中? - How can I verify that a git project's release branch's fixes have all been merged into master? 在子分支已合并回master之后,VSTS Git将孙分支合并到master - VSTS Git merge grandchild branch into master after child branch has been merged back into master 如何检查master是否已合并到当前分支 - How do I check if master has been merged into current branch 如果其他分支已合并到主分支,如何将我的分支合并到主分支 - How to merge my branch to master if some other branch has been merged into the master 如何将远程主服务器重置回尚未与git中的另一个分支合并的提交 - How to reset remote master back to a commit which has not been merged with another branch in git
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM