简体   繁体   English

git:如果已将分支推送到日志中并且不存在,如何还原将一个分支移动到另一分支的操作

[英]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: 假设我有两个分支:

  • branch: master 分行:硕士
  • branch: branchX 分支:branchX

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: 在这种情况下,您需要:

  • checkout master : git checkout master 结帐mastergit checkout master
  • merge 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: 您可以通过以下方式进行清洁:

  • deleting the local branch: 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中进行一些更改,这些更改尚未集成,并且由于删除分支而丢失。
  • deleting the branch on your remote as well: 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.

相关问题 Git - 如何恢复已推送到远程分支(不是原点)的变基 - Git - How to revert a rebase that has been pushed to the remote branch (not origin) 从已推送的合并分支恢复特定提交 - Revert a specific commit from a merged branch that has already been pushed 如何还原已在GIT中推送的单个已提交文件? - How to revert a single committed file that has been pushed in GIT? Git:如何删除已经提交,推送并合并到master的分支? - Git: How do I remove a branch that has already been committed, pushed, and merged into master? 仅构建已推送到的Git分支 - Build only the Git branch that has been pushed to 修改已经推送到 Git 中的代码 - Modifying code that has already been pushed in Git 如何恢复已经推送到远程分支的合并提交? - How to revert a merge commit that's already pushed to remote branch? Git - 如何查看分支是否已合并到另一个分支? - Git - How to see if a branch has EVER been merged into another branch? 恢复一个git分支以反映另一个 - Revert one git branch to reflect another 如果已经运行了来自其他分支的更高版本的迁移,那么如何在Heroku上运行从Git分支进行的迁移? - How does a migration from a Git branch get run on Heroku if a later migration from a different branch has already been run?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM