简体   繁体   English

我怎么知道 git 中的分支是否已经重新定位到 master?

[英]How can I know in git if a branch has been already rebased onto master?

This is very similar to How can I know in git if a branch has been already merged into master?这与How can I know in git if a branch has been already merged into master?非常相似。 but is about checking for rebased code.但是是关于检查重新设置代码的。 In the repository I am currently working on it seems that a few feature branches have been left hanging aground after their changes were rebased onto master.在我目前正在处理的存储库中,似乎有一些功能分支在它们的更改重新基于 master 后被搁置了。 What is the best way for me to check that this has been done before I delete the branch?在删除分支之前检查是否已完成的最佳方法是什么?

Most of the suggestions on that branch suggest using the SHA id key of the last change on a branch to check for its presence in master.该分支上的大多数建议建议使用分支上最后一次更改的 SHA id 密钥来检查它是否存在于 master 中。 I can see that is the best way to be sure for merging but when you rebase this SHA is changed.我可以看到这是确保合并的最佳方法,但是当您重新设置此 SHA 时,它会发生变化。

I have an answer that I will post too but I would like to know if people think there are better options.我也将发布一个答案,但我想知道人们是否认为有更好的选择。

In a case where the rebases are faithful to the original commit message @TafT's answer will work well. 如果rebase忠实于原始提交消息,@ TafT的答案将会很好。 In addition, using 另外,使用

git log --oneline --cherry master...some-branch

will show = by every commit that has been copied exactly the same from some-branch to master. 将显示=每个从某个分支到主分支完全相同的提交。

If squashing and the like is taking place, commit messages are changed, or if your rebasing had conflicts neither solution will work. 如果正在进行压缩等,则会更改提交消息,或者如果您的变基有冲突,则解决方案都不起作用。 In this case I suggest the following (Checkout to detached HEAD so that we do not accidentally push this merge): 在这种情况下,我建议以下(Checkout分离HEAD,以便我们不会意外推送此合并):

git checkout master~0
git merge some-branch

Unless your code has changed drastically, if the merge results in no change, then the branch has been rebased already. 除非您的代码发生了巨大变化,否则如果合并没有发生变化,那么分支已经重新定位。 Otherwise, it obviously has not. 否则,它显然没有。

Searching by the last commit message of the feature branch within the master branch's log works quite well. 通过主分支日志中的功能分支的最后一次提交消息进行搜索非常有效。

On the master branch do: 在主分支上做:

 git log -i --grep="<summary>"

Where 哪里 is a segment of the comment from the last commit in your feature branch. 是功能分支中最后一次提交的注释的一部分。 This presents you with the commit SHA for the master branch copy, the Author and Date of the commit; 这将为您提供主分支副本的提交SHA,提交的作者和日期; the last two of which are preserved by a rebase. 最后两个由rebase保留。 If your Author, Date and Comments are similar then you can be confident that the change was rebased onto the branch who's log you are inspecting. 如果您的作者,日期和评论相似,那么您可以确信更改已重新定位到您正在检查的日志的分支上。

This will not work if the rebase was used to squash all the feature branch commits into a single commit on master. 如果使用rebase将所有功能分支提交压缩到master上的单个提交中,则这将不起作用。

There are possibly other issues with this method, please do post them in the comments or suggest better answers where you can. 此方法可能存在其他问题,请在评论中发布或在可能的地方提出更好的答案。

You can also rebase the feature branch onto the master branch.您还可以将功能分支变基到主分支上。 If it was already rebased, the feature branch will not have any more commits in front of master after the rebase, but point to the same commit as master.如果已经rebase了,feature分支在rebase之后不会再有master前面的commit,而是指向和master一样的commit。 If the feature branch has master as upstream ( git branch --set-upstream-to=master ), you can then safely delete the branch with git branch -d feature-branch and git will make sure that there are no dangling commits.如果 feature 分支有 master 作为上游( git branch --set-upstream-to=master ),您可以使用git branch -d feature-branch安全地删除分支, git 将确保没有悬空提交。

暂无
暂无

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

相关问题 我如何知道一个分支是否已经合并到 master 中? - How can I know if a branch has been already merged into master? Git:如何删除已经提交,推送并合并到master的分支? - Git: How do I remove a branch that has already been committed, pushed, and merged into master? 使用git svn,我只是将功能分支重新设置为master和fast forwarding master。 如何检查我的主人的历史是否是线性的? - Using git svn, I just rebased feature branch onto master and fast forwarded master. How do I check that my master's history is linear? Git:我忘记创建分支 master,如果我的存储库已经有另一个分支,我该如何创建它? - Git: i forgot create branch master, how i can create it if my repository already has another branch? 我怎么知道分支是否已经在SVN / Mercurial / Git中合并? - How do I know if a branch has already been merged in SVN/Mercurial/Git? 该(重新设置的)分支是否已合并? - Has this (rebased) branch been merged? git:将分支变基到其变基的父级 - git: rebase branch onto its rebased parent 已经与master合并的分支中的错误如何解决? - How to fix a bug in a branch after it has already been merged with master? 我不小心一直在 master 上工作,如何将我对分支重置 master 所做的所有更改转移到最后一次提交? - I've accidentally been working on master, how can I transfer all the changes I made onto a branch reset master to the last commit? 您如何处理已经重新定位的公共存储库? - How do you deal with a public repository that has already been rebased?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM