简体   繁体   English

我不小心将 Repo1 的 Master 分支拉到本地并将 Remote 更改为 Repo2 并推送到特定分支。 如何恢复这个?

[英]I Accidentally Pulled Master branch Of Repo1 Into local and changed Remote to Repo2 and pushed to specific Branch. How to Revert This?

I Had to -我不得不 -

  1. Clone Branch 2 from of repo 1.来自 repo 1 的克隆分支 2。
  2. Change the Remote Origin of Local repo 2.更改本地 repo 2 的远程来源。
  3. Push Code to branch 1 of repo 2.将代码推送到 repo 2 的分支 1。

I Did -我做了-

  1. Clone Branch 1(master) from of repo 1.来自 repo 1 的克隆分支 1(主)。
  2. Change the Remote Origin of Local repo 2.更改本地 repo 2 的远程来源。
  3. Write Code.编写代码。
  4. Push Code to branch 1 of repo 2.将代码推送到 repo 2 的分支 1。

I don't care if my code loses, I just Want to Re-do This Process without any branch conflicts我不在乎我的代码是否丢失,我只想在没有任何分支冲突的情况下重新执行此过程

Perform these steps执行这些步骤

  1. git log // then copy the commit id at which the state of your branch is correct . git 日志 // 然后复制提交 id,您的分支的 state 是correct的。

  2. git reset --hard commitId git 重置 --hard commitId

  3. git push -f git 推-f

In case you don't want to lose the code:如果您不想丢失代码:

  1. git log // then copy the commit id at which the state of your branch is correct . git 日志 // 然后复制提交 id,您的分支的 state 是correct的。

  2. git reset --soft commitId git 重置 --soft commitId

  3. git reset. git 复位。

  4. git stash //saving the work git stash //保存工作
  5. git reset --hard //Erase everything git reset --hard //擦除所有内容
  6. git push -f git 推-f

Now clone the correct repository and apply: git stash pop //this will bring in the changes on the intended repository现在克隆正确的存储库并应用: git stash pop //这将在预期的存储库中引入更改

solve if there are any merge conflicts.解决是否存在任何合并冲突。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 有人能告诉我如何让我的本地仓库上的主分支反映远程仓库上的主分支吗? - Can someone tell me how I can get the master branch on my local repo to reflect the master branch on the remote repo? 目前尚不存在如何从派生存储库到本地的远程分支以及从中推送分支的当前派生存储库的方式 - How to fetch a remote branch from forked repo to local, and currently forked repo from which branch is pushed is not exist 本地 git 远程仓库丢失主分支 - local git remote repo lost master branch 简单地将本地 repo 添加到远程 repo 的主分支(不是 master) - Simple add local repo to remote repo's main branch (not master) 我的本地分支在 master 上,我推送到 main 上的远程仓库,但现在我收到“非快进”错误 - My local branch was on master and I pushed to my remote repo that was on main but now I'm getting a 'non-fast-forward' error 我有一个分支的git repo:master。 如何在本地和远程仓库上重命名分支? - I have git repo with one branch: master. How do I rename the branch locally and on the remote repo? 如何还原将本地分支推送到远程主服务器 - How to revert pushing local branch to remote master 我有一个远程起源分支。 在本地,我有一个主分支和测试分支。 如何在不提交的情况下拉到测试分支? - I have a remote origin branch. Locally I have a master branch and test branch. How to pull to test branch without committing? 如何将本地Git分支复制到远程仓库 - How to copy a local Git branch to a remote repo 我克隆了一个远程分支。 我如何结帐大师? - I cloned a remote branch. How do I checkout master?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM