我正在使用BitBucket.Already我推了一个分支来掌握并与master.Now合并,现在我需要恢复从master.推荐的分支做到这一点?如何恢复从主的合并分支?
在我的情况:我必须恢复最后五个提交,我需要返回以前的代码。如何删除或恢复提交?
注意:目前我没有任何分支,因为已经与主合并并删除了分支。我只有一个主分支。
是否有可能再次恢复合并分支?
我正在使用BitBucket.Already我推了一个分支来掌握并与master.Now合并,现在我需要恢复从master.推荐的分支做到这一点?如何恢复从主的合并分支?
在我的情况:我必须恢复最后五个提交,我需要返回以前的代码。如何删除或恢复提交?
注意:目前我没有任何分支,因为已经与主合并并删除了分支。我只有一个主分支。
是否有可能再次恢复合并分支?
好的,所以你需要做一个强制推动来解决这个问题。我不会做合并的回复,这会给你带来问题。请注意,强制推送意味着您正在重写历史记录,因此您需要让其他开发人员知道您正在执行此操作。
1./ reset master back to the master side parent commit
2./ recover your private branch, so you don't lose your commits.
3./ force push master.
此图有希望说清楚。
感谢您的帮助..我解决了 –
这将有助于了解您的历史是什么样子。我将使用的地牢抓取的历史作为一个例子,告诉你如何撤消合并提交:
比方说,它目前看起来是这样的:
$ git log --graph --online --decorate -n 5
* 94e1b85 (HEAD, master) Merge branch 'next'
|\
| * 9312efc Don't generate Lehudib's crystal spear the unrand.
| * 518382a Make Sticks to Snakes only work on missiles
| * 6e8ccac Let monsters pick up Elf:$ loot
* | 9ca6e02 Distinct manual tiles
* | a16bb39 Restore trunk changelog entries removed by 673ecc60.
* | 1d9921b Touch the 0.13 changelog header with the tentative release date.
你会发现git log --oneline --graph --decorate
用武之地了。 --graph
将帮助你看到分支&合并,--oneline
只是保持简短,--decorate
将分支和标签名称注释到提交。 (这是一个非常有用的命令,我为此稍微定制了一个版本的别名。)
看到94e1b85
提交?这是一个合并提交。假设我们想撤消它。让我们备份的东西,以防万一:
# Save master, just in case:
$ git checkout master
$ git branch old-master
首先,让我们恢复旧的分支。我打算叫它other-branch
。或者:
$ git branch other-branch master^2
这意味着“创建一个名为other-branch
新的分支,在提交这是master
第二(2
)父(^
)你也可以通过哈希,你可以看到它命名。在git log
命令我上面使用
$ git branch other-branch 9312efc
历史应该像:
$ git log --graph --online --decorate -n 5
* 94e1b85 (HEAD, master) Merge branch 'next'
|\
| * 9312efc (other-branch) Don't generate Lehudib's crystal spear the unrand.
| * 518382a Make Sticks to Snakes only work on missiles
| * 6e8ccac Let monsters pick up Elf:$ loot
* | 9ca6e02 Distinct manual tiles
* | a16bb39 Restore trunk changelog entries removed by 673ecc60.
* | 1d9921b Touch the 0.13 changelog header with the tentative release date.
现在,更改其中master
点:
$ git checkout master $$ git reset --hard HEAD^
(你可以提交哈希更换HEAD^
这里。在^
之后有一个隐含的1
。)
请与您的工作:
$ git log --oneline --graph -n 120 --decorate old-master
* 94e1b85 (old-master) Merge branch 'next'
|\
| * 9312efc (other-branch) Don't generate Lehudib's crystal spear the unrand.
| * 518382a Make Sticks to Snakes only work on missiles
| * 6e8ccac Let monsters pick up Elf:$ loot
* | 9ca6e02 (HEAD, master) Distinct manual tiles
* | a16bb39 Restore trunk changelog entries removed by 673ecc60.
* | 1d9921b Touch the 0.13 changelog header with the tentative release date.
一旦你得到的东西你想要的状态,把它推至到位桶你将最有可能需要git push --force origin master
。 请注意:这将强制将Bitbucket上的主设置为您使用上述设置的任何设置。 另外:我们正在有效地重写历史。如果其他人对我们撤销的合并提交进行了更改,我们将为他们带来问题。 (他们需要将他们的承诺重新分配到我们刚刚重新编写的历史记录中。)
感谢您的帮助..我解决了 –
您能向我们展示您的历史记录吗?类似于'git log -n 10 --oneline --graph'的输出,可能带有关于你想改变什么的注释? – Thanatos