简体   繁体   English

Git:分支但父分支已更改

[英]Git: branched off but parent branch has changed

Here is my scenario: 这是我的情况:

git checkout master

git pull

Now master is up to date. 现在, master是最新的。

We create a new branch and switch to it: 我们创建一个新分支并切换到它:

git branch test

git checkout test

As of this point, test and master should be identical, with test being a local branch not visible to remote/origin . 至此, testmaster应该是相同的, test是对remote/origin不可见的本地分支。 (Correct me if this is wrong, but I see no reason why it should be) (如果这是错误的,请更正我,但我认为没有理由这样做)

Now, somewhere along the way, master is merged with additional branches that affect files that you are working on locally in test . 现在,在此过程中的某个地方, master与其他分支合并,这些分支会影响您正在test本地处理的文件。 My question is: 我的问题是:

Aside from git stash ing the changes so far, deleting the local test branch, and branching off from master again , what is the best way to merge the new changes from master into the local test branch? 除了git stash到目前为止的更改,删除本地test分支并再次master分支之外,将新更改从master合并到本地test分支的最佳方法是什么?

As you already mentioned your could merge master into test by 正如您已经提到的,您可以通过以下方式将master合并到test

git checkout test
git merge master

which will collect the changes on master branch and apply them in one merge commit on test . 它将在master分支上收集更改,并将它们应用于test一个合并提交中。

Instead you could also run git rebase master test which will reapply the commits in test onto the new master and give you a linear history. 相反,你也可以运行git rebase master test将重新在提交test到新master ,并给你一个线性的历史。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM