如何使用git重新设置两个分支的基础?

如何使用git重新设置两个分支的基础?,git,Git,我正在尝试将master重新设置为dev: git rebase master 然后我得到:当前分支是最新的 然而,当我检查两个分支之间的差异时,我得到了一个冲突。为什么git不说冲突检测之类的话 另请参见此处获取代码我无法对您的问题发表评论,因此这可能无法回答您的所有问题 1您的rebase命令按预期工作。您在一个开发分支上,该分支在主分支上有一个提交。它已经是最新的,没有什么可以在那里重新设置基础 2不太清楚你所说的是什么意思,你看到两个分支之间存在冲突。但是,我假设您可能希望将更改从de

我正在尝试将master重新设置为dev:

git rebase master
然后我得到:当前分支是最新的

然而,当我检查两个分支之间的差异时,我得到了一个冲突。为什么git不说冲突检测之类的话


另请参见此处获取代码

我无法对您的问题发表评论,因此这可能无法回答您的所有问题

1您的rebase命令按预期工作。您在一个开发分支上,该分支在主分支上有一个提交。它已经是最新的,没有什么可以在那里重新设置基础

2不太清楚你所说的是什么意思,你看到两个分支之间存在冲突。但是,我假设您可能希望将更改从dev部署到master分支。如果是,以下是步骤:

git checkout master       // Switch the current branch to master
git merge dev             // Merge the dev branch to master (it will be just fast-forward)
git push origin master    // Push to origin

现在master和dev分支应该保持相同的提交状态。

如果您的目的是将分支dev合并到master中,只显示一个提交和一个注释,那么您需要添加选项-interactive。 因此,从dev分支运行的命令变成:

git rebase master --interactive
通过这种方式,您可以压缩要隐藏的提交

# This is a combination of 4 commits.
# The first commit's message is:
Adding the book delete function
# This is the 2nd commit message:
# Creating the unit test for book add function
# This is the 3rd commit message:
# Now the function is finished
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# Explicit paths specified without -i nor -o; assuming --only paths...
# Not currently on any branch.
因此,例如,当您找回此代码时:

pick 01d1124 Adding the book add function
pick 6340aaa Creating the unit test for book add function
pick ebfd367 Now the function is finished
# Rebase 60709da..30e0ccb onto 60709da
#
# Commands:
#  p, pick = use commit
#  e, edit = use commit, but stop for amending
#  s, squash = use commit, but meld into previous commit
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
#
您可以这样编辑代码:

pick 01d1124 Adding the book delete function
squash 6340aaa Creating the unit test for book add function
squash ebfd367 Now the function is finished
然后在所有要隐藏的注释之前放置一个

# This is a combination of 4 commits.
# The first commit's message is:
Adding the book delete function
# This is the 2nd commit message:
# Creating the unit test for book add function
# This is the 3rd commit message:
# Now the function is finished
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# Explicit paths specified without -i nor -o; assuming --only paths...
# Not currently on any branch.
然后你结帐,然后

通过这种方式,只需一次提交,就可以将分支dev合并到master中

您为什么会收到当前分支机构的最新消息

您可以使用git-rebase来更新分支开发人员,在从主节点实例化开发人员之后,使用在分支主节点上完成的提交来更新分支开发人员。 在分支*dev**上执行以下操作:

git rebase master
如果在那一刻之后您没有在master上执行任何新的提交,您将收到以下消息: 当前分支是最新的

这是因为在较低的级别上,rebase实际上是一个接一个地提取在主分支上完成的新提交,并将它们重新附加到dev的最后一次提交

因此,如果您没有挤压任何提交,那么该命令将无效

我发现本文中包含的图像对于理解机制非常有用:

这是因为开发分支已经从master提交了5bc2e51138f6827c6654e468a05b875e3c81edf3,这是master中唯一的提交。它与master同步,或者你可以说在master之前提交1次,然后发送消息。你说检查两个分支之间的差异是什么意思?因为这两个分支之间存在冲突,我希望在rebase中发送消息?当您进行合并时,有一种合并方式,例如分支之间的冲突等。是否应该为重基设置1?如果您与主分支重基的分支有新的提交和相同的行更改,则合并和重基都可能导致冲突。您的主分支位于开发人员的后面,并且没有新的提交,因此对重新基础操作没有冲突。如果否决此答案的人能够解释合理的原因,那就太好了。这将有助于我下次改进我的答案。