Git pull origin <branch> 覆盖主人?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16473805/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 16:07:39  来源:igfitidea点击:

Git pull origin <branch> overwrites master?

gitgithubgit-branchremote-branch

提问by Jeff

I have a repository on Github, aav1

我在 Github 上有一个仓库,aav1

On my laptop I have two branches, one called masterand one called vs12upThe master branch was when the software was Visual Studio 2008, vs12up is converted to Visual Studio 2012.

在我的笔记本电脑上,我有两个分支,一个叫做master,一个叫做vs12upmaster 分支是当软件是 Visual Studio 2008 时,vs12up 转换为 Visual Studio 2012。

On my laptop everything seems fine and I pushed the new branch to github, appears correct.

在我的笔记本电脑上一切正常,我将新分支推送到 github,看起来正确。

On my desktop I tried to pull the remote branch:

在我的桌面上,我尝试拉远程分支:

git pull origin vs12up

It wrote the changes to my master branch on the desktop, git logshows the commits made on the vs12upbranch, but git branch only shows master, which is the current branch.

它在桌面上将更改写入我的 master 分支,git log显示在vs12up分支上所做的提交,但 git branch 仅显示master,即当前分支。

How can I revert the changes to the masterbranch and pull the vs12upbranch on my desktop to match the repository on my laptop?

如何恢复对master分支的更改并拉取桌面上的vs12up分支以匹配笔记本电脑上的存储库?

回答by earl

If you do a git pullwith a remote branch name, it will fetch the remote branch and then merge it into your current local branch. So to undo that, you will first have to reset your local branch to the remote master, then create a new local vs12upbranch from the corresponding remote branch.

如果您git pull使用远程分支名称执行 a ,它将获取远程分支,然后将其合并到您当前的本地分支中。因此,要撤消该操作,您首先必须将本地分支重置为 remote master,然后vs12up从相应的远程分支创建一个新的本地分支。

  1. Reset your local masterto match the remote repository's master(WARNING: be sure that you don't have any uncommitted changes you want to keep before issuing the following command):

    git reset --hard origin/master
    
  2. Fetch all remote branches into your local repository:

    git fetch origin
    
  3. Create a new local vsup12branch from the remote vsup12branch, and switch to this new local branch:

    git checkout -b vsup12 origin/vsup12
    
  1. 重置您的本地master以匹配远程存储库的master(警告:在发出以下命令之前,请确保您没有任何要保留的未提交更改):

    git reset --hard origin/master
    
  2. 将所有远程分支提取到您的本地存储库中:

    git fetch origin
    
  3. vsup12从远程vsup12分支创建一个新的本地分支,并切换到这个新的本地分支:

    git checkout -b vsup12 origin/vsup12
    

Note that when you subsequently just do a git pullwhile switched to the vsup12branch, you'll fetch and merge the latest changes from the vsup12branch on Github into your local vsup12

请注意,当您随后git pull切换到vsup12分支时,您将从vsup12Github 上的分支获取最新更改并将其合并到您的本地vsup12