[英]git: how to revert the operation of moving one branch to another if it has been already pushed and it does not exist in the log
Let's say I have two branches: 假设我有两个分支:
I wanted to move the files of branchX to master. 我想将branchX的文件移至master。 Then delete branchX. 然后删除branchX。 I typed ( I did not used merge , unfortunately): 我输入了( 很遗憾, 我没有使用过merge ):
git branch -f master branchX
git push REMOTE_GIT_URL branchX master
Unfortunately the result was the opposed than expected: branchX has the content of master now. 不幸的是结果是与预期相反的:branchX现在拥有master的内容。 I have typed git log
, but it does not show any of these operations. 我输入了git log
,但是它没有显示任何这些操作。
Which command was wrong? 哪个命令错了? Should I use the command merge
instead? 我应该使用命令merge
吗? How to revert it? 如何还原?
Note: I did not trusted myself, so I downloaded a zipped copy of branchX previously. 注意:我不信任自己,因此以前下载了branchX的压缩副本。 Anyway I want to learn what I did wrong! 无论如何,我想了解我做错了什么!
If you want to include the work done in branchX
into master
, this is called merging . 如果您想将branchX
完成的工作包含在master
,则称为合并 。 You want to merge branchX
into master
. 您想要将branchX
合并到master
。
In that case you need to: 在这种情况下,您需要:
master
: git checkout master
结帐master
: git checkout master
branchX
into it: git merge branchX
将branchX
合并到其中: git merge branchX
Once this is correct locally (and only then), you can push your newly updated master
to your remote repo: 一旦这在本地是正确的(并且只有这样),您可以将新近更新的master
推送到远程仓库中:
git push REMOTE_GIT_URL master
(with your local master
still checked out) git push REMOTE_GIT_URL master
(您的本地master
仍处于检出状态) As you write, branchX
is not needed anymore, since its work is integrated to master
. 在您编写时,不再需要branchX
,因为它的工作已集成到master
。 You can clean by: 您可以通过以下方式进行清洁:
git branch -d branchX
. 删除本地分支: git branch -d branchX
。 This should work with no warning, otherwise you have changes in branchX
that were not integrated and would be lost by deleting the branch. 这应该在没有警告的情况下起作用,否则您将在branchX
中进行一些更改,这些更改尚未集成,并且由于删除分支而丢失。 git push REMOTE_GIT_URL :branchX
. 删除您的遥控器上的分支: git push REMOTE_GIT_URL :branchX
。 Note the syntax, you are pushing nothing (left side of the :
) on to remote branchX
, this is how you delete branches on remotes. 注意语法,你推什么 (左侧的:
)到远程branchX
,你这是怎么删除遥控器的分支。 Only do this after you have pushed master
, so that the remote also has the new master
where branchX
is integrated. 仅在按下master
之后执行此操作,以便远程服务器也具有集成了branchX
的新master
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.