如何更新 git 分支以匹配 master?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16890271/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 08:35:17  来源:igfitidea点击:

How do I update a git branch to match master?

git

提问by cb23er4

Here's my problem. I have a branch off master, and i made some changes. A little later my partner reverted a change they had made because it was breaking something. When i ran git fetch; git rebase mastermaster was fixed and everything was okay. But when I ran git fetch; git rebase my_featurethe my_featurebranch still had the same problems as before. How can i update the my_featurebranch so that it takes into account the reverted commit? Thanks!

这是我的问题。我有一个 master 分支,我做了一些改变。过了一会儿,我的搭档恢复了他们所做的更改,因为它破坏了某些东西。当我跑的时候,git fetch; git rebase master主人是固定的,一切都很好。但是当我运行git fetch; git rebase my_featuremy_feature分支时,仍然遇到与以前相同的问题。我如何更新my_feature分支以便它考虑到恢复的提交?谢谢!

回答by g19fanatic

You first need to git fetch and git merge your master branch that is following the remote master branch. You can do this with git checkout masterthen git pull origin master. This will bring your master branch up to a place that is equilivant with the remote repository.

您首先需要 git fetch 和 git merge 跟随远程 master 分支的 master 分支。你可以用git checkout masterthen做到这一点git pull origin master。这会将您的主分支带到与远程存储库等效的位置。

Then you will need to do the following to rebase your feature branch ontop of the new commits (a git revert is just another commit to a branch and should be treated the same as any other commit (with special concerns depending on the situation)): git checkout my_featurethen git rebase master.

然后,您需要执行以下操作以将您的功能分支重新定位到新提交的基础上(git revert 只是对分支的另一个提交,应与任何其他提交一样对待(根据情况有特殊问题)): git checkout my_feature然后git rebase master

This will rebase your feature branch ontop of the new local master branch which should be tracking the remote master branch.

这会将您的功能分支重新定位到新的本地主分支之上,该分支应该跟踪远程主分支。

回答by Guillaume Darmont

Since you branched my_featureoff master, you have to do a git rebase origin/masterwhile being on my_featurebranch.

既然你分支my_featuremaster,你必须git rebase origin/mastermy_feature分支上做一段时间。

回答by hlovdal

If the master branch before had commits

如果之前的主分支有提交

(A) --> (B) --> (C) --> (D)

and the my_featurebranch was based on (D), which is now reverted so that (C)is the latest commit on master, then you can rebase my_featureonto (C)by running

my_feature分支的基础上(D),现在恢复,这样(C)是最新提交的高手,那么你可以变基my_feature(C)运行

git branch my_feature.orig my_feature                          # optional, delete this branch when satisfied
git rebase --onto master $SHA1_OF_COMMIT_D my_feature.