如果 bitbucket 中的 master 和 branch 都发生了变化,合并时会发生什么
what will happen when merge, if both master and branch has changed in bitbucket
我在本地机器上有一个来自 master 的分支。我知道如何 merge
掌握回购协议。但问题是这个。
认为其他开发人员通过将更改推送到主存储库来更改主存储库,同时我将按分支将更改合并到主存储库。
What will happen at this situation.
遇到这种情况我该怎么办。我试着从我的分支做以下事情。
- 添加了我的更改 ->
git add *
- 然后提交 ->
git commit -m "my commit"
- 然后用 ->
git push -u origin my_branch_name
推送到我的分支
- 然后使用 ->
git checkout master
将存储库更改为 master
- 然后将分支合并到 master ->
git merge my_branch_name
到这个阶段就成功了。然后我尝试使用以下命令推送(几分钟前,另一位开发人员已推送到 master)
git push origin master
然后是下面的内容
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'git@bitbucket.org:abcdef/cups.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
现阶段,我该怎么办。
- 我应该在合并步骤后得到一个
pull
然后推送(在这个阶段如果我得到一个拉,会发生什么。)还是
- 我是否必须做
git stash
之类的事情,然后 push
之类的事情。
希望您对此有所帮助。非常感谢。
您需要将对方推送的作品取回并在本地集成后才能推送。
您可以直接执行 "git pull",或者更好地执行 "git fetch",然后执行 "git merge" 或 "git rebase"。
fetch 的优点是允许您查看其他用户推送了哪些提交。然后您可以决定进行合并或变基。 rebase 的优点是生成 "cleaner" 树。
如果您有一些正在进行的工作(已暂存的文件),您需要决定是否要将其整合到下一次推送中。然后您需要决定丢弃它们、隐藏它们或将它们集成到您的下一次提交中。
您需要 Pull remote/master
(以获取所有远程更改),然后您才能推送本地更改。
说,当你拉取 remote/master
时有 2 次提交 (A, B)
remote/master: A -> B
local/master: A -> B
然后其他开发人员将提交 P
推送到 master
remote/master: A -> B -> P
local/master: A -> B
然后你在你的分支中提交了 X
(比如,feature
)
remote/master: A -> B -> P
local/master: A -> B
local/feature: A -> B -> X
现在将您的 feature
与 local/master
合并
remote/master: A -> B -> P
local/master: A -> B -> X
local/feature: A -> B -> X
现在您必须拉取 remote/master
以将 remote/master 的所有提交提取到 local/master.
remote/master: A -> B -> P
local/master: A -> B -> P -> X # now local/master has P (sync with remote/master)
local/feature: A -> B -> X
将您的local/master推送到远程
remote/master: A -> B -> P -> X
local/master: A -> B -> P -> X
local/feature: A -> B -> X
我在本地机器上有一个来自 master 的分支。我知道如何 merge
掌握回购协议。但问题是这个。
认为其他开发人员通过将更改推送到主存储库来更改主存储库,同时我将按分支将更改合并到主存储库。
What will happen at this situation.
遇到这种情况我该怎么办。我试着从我的分支做以下事情。
- 添加了我的更改 ->
git add *
- 然后提交 ->
git commit -m "my commit"
- 然后用 ->
git push -u origin my_branch_name
推送到我的分支
- 然后使用 ->
git checkout master
将存储库更改为 master
- 然后将分支合并到 master ->
git merge my_branch_name
到这个阶段就成功了。然后我尝试使用以下命令推送(几分钟前,另一位开发人员已推送到 master)
git push origin master
然后是下面的内容
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'git@bitbucket.org:abcdef/cups.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
现阶段,我该怎么办。
- 我应该在合并步骤后得到一个
pull
然后推送(在这个阶段如果我得到一个拉,会发生什么。)还是 - 我是否必须做
git stash
之类的事情,然后push
之类的事情。
希望您对此有所帮助。非常感谢。
您需要将对方推送的作品取回并在本地集成后才能推送。 您可以直接执行 "git pull",或者更好地执行 "git fetch",然后执行 "git merge" 或 "git rebase"。 fetch 的优点是允许您查看其他用户推送了哪些提交。然后您可以决定进行合并或变基。 rebase 的优点是生成 "cleaner" 树。
如果您有一些正在进行的工作(已暂存的文件),您需要决定是否要将其整合到下一次推送中。然后您需要决定丢弃它们、隐藏它们或将它们集成到您的下一次提交中。
您需要 Pull remote/master
(以获取所有远程更改),然后您才能推送本地更改。
说,当你拉取
remote/master
时有 2 次提交 (A, B)remote/master: A -> B local/master: A -> B
然后其他开发人员将提交
P
推送到 masterremote/master: A -> B -> P local/master: A -> B
然后你在你的分支中提交了
X
(比如,feature
)remote/master: A -> B -> P local/master: A -> B local/feature: A -> B -> X
现在将您的
合并feature
与local/master
remote/master: A -> B -> P local/master: A -> B -> X local/feature: A -> B -> X
现在您必须拉取
remote/master
以将 remote/master 的所有提交提取到 local/master.remote/master: A -> B -> P local/master: A -> B -> P -> X # now local/master has P (sync with remote/master) local/feature: A -> B -> X
将您的local/master推送到远程
remote/master: A -> B -> P -> X local/master: A -> B -> P -> X local/feature: A -> B -> X