git 使用远程主更新本地主

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36540645/
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-09 04:05:04  来源:igfitidea点击:

updating local master with remote master

gitgithub

提问by joey

I have a branch that I want to merge to the remote, most up-to-date master. I have a local, outdated master on my computer. I ran git pull upstream master, and it retrieved the remote master, and that was great, exactly what I wanted. Then, without thinking, i accidentally discarded the changes while switching to another branch.

我有一个分支,我想合并到远程的、最新的master. 我的计算机上有一个本地过时的主机。我跑了git pull upstream master,它找回了遥控器master,这很棒,正是我想要的。然后,没想到,我在切换到另一个分支时不小心丢弃了更改。

While on my local master, I have run git pull, and git pull upstream mastermany times now, and it always says "Already up to date." when it clearly isn't. At first git pull upstream masterworked just fine, but now it doesn't, and the machine thinks it is up to date when it isn't. How can I make my local master the same as the remote one again?

虽然在我的本地主人,我已经运行git pull,而git pull upstream master现在许多次,它总是说“已经是最新的。” 当它显然不是。起初git pull upstream master工作得很好,但现在不行了,机器认为它是最新的,而不是最新的。我怎样才能让我的本地主机再次与远程主机相同?

回答by Som Bhattacharyya

Well, typically when I have an outdated master locally and want to merge recent changes in a branch (say, my_branch) to master (both locally and remotely), I do the following,

好吧,通常当我在本地有一个过时的 master 并且想要将分支(例如 my_branch)中的最新更改合并到 master(本地和远程)时,我会执行以下操作,

  • Checkout the masterbranch locally.
  • Run git pull --rebase origin master(This pulls down the most up-to-date changes on master locally)
  • Checkout local branch say my_branch
  • Run git pull --rebase origin master(This updates your local branch against the most recent master on remote. You may need to resolve the conflicts here (if any that is))
  • checkout the masterbranch locally, again.
  • Run git merge my_branch
  • Run git push origin master
  • master本地结帐分支。
  • 运行git pull --rebase origin master(这会在本地拉取 master 上的最新更改)
  • 结帐当地分行说 my_branch
  • 运行git pull --rebase origin master(这会根据远程上的最新主节点更新您的本地分支。您可能需要解决此处的冲突(如果有的话))
  • master再次在本地结帐分支。
  • git merge my_branch
  • git push origin master

回答by Gianni Carlo

If you have already done a git fetch upstreamYou can try doing while in your branch master:

如果你已经做了一个git fetch upstream你可以在你的分支 master 中尝试做:

 git reset --hard upstream/master

This will set your current branch to be exactly like your upstream master (it will discard any local changes btw). Check your last commit to confirm that you've got the latest in your local

这会将您当前的分支设置为与您的上游 master 完全一样(顺便说一下,它将丢弃任何本地更改)。检查您的最后一次提交以确认您在本地获得了最新的提交

回答by Hitesh

Below worked for me like charm

下面像魅力一样对我有用

  1. git checkout master
  2. git pull
  3. git checkout <your local branch>
  4. git pull --rebase --autostash origin master
  1. git checkout master
  2. git pull
  3. git checkout <your local branch>
  4. git pull --rebase --autostash origin master