git 如何合并回远程分支

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

How do I merge back into remote branch

gitgithub

提问by MikeW

I have these 2 branches on my remote GitHub repository:

我的远程 GitHub 存储库中有这 2 个分支:

  • development
  • master
  • 发展
  • 掌握

How do I merge development into master on the remote repository? I've tried

如何将开发合并到远程存储库上的 master 中?我试过了

git merge development

and

git merge origin

but it says the repo is up to date so I'm doing it wrong because github says development is 12 commits ahead of master.

但它说 repo 是最新的,所以我做错了,因为 github 说开发比 master 早 12 次提交。

Update

更新

Thanks for the follow ups - here's some more info, I did a push to the remote repository with

感谢您的跟进 - 这里有更多信息,我使用以下命令推送到远程存储库

git push origin 

and my changes have been committed. If I do a clone in another folder I see all the changes there if I checkout the development branch.

我的更改已经提交。如果我在另一个文件夹中进行克隆,如果我签出开发分支,我会看到那里的所有更改。

git branch -av 
development      8265e30 - etc
hotfix-t4        8342e44 - etc 
*master          0041bod - Initial Commit
  remotes/origin/HEAD  -> origin/master
  remotes/origin/development 8265e30 - etc
  remotes/origin/experimental 22cd3ef test1
  remotes/origin/hotfix-t4 8342e44 test
  remotes/origin/master 0041bod Initial commit

回答by Mark Longair

The behaviour of git pushor git push origin(i.e. when you don't also specify a refspec as the last parameter) is rather surprising - by default it pushes each branch to one of the same name so long as a branch with that name exists both locally and remotely. (This default can be changed with the push.defaultconfig option.)

git pushor的行为git push origin(即,当您还没有将 refspec 指定为最后一个参数时)是相当令人惊讶的 - 默认情况下,它会将每个分支推送到同名之一,只要具有该名称的分支在本地和远程都存在。(可以使用push.defaultconfig 选项更改此默认值。)

So, to be sure that you have correctly pushed a particular branch to the same name in the remote origin, it's a good idea to always use this form:

因此,为了确保您在 remote 中正确地将特定分支推送到同名origin,最好始终使用以下形式:

git push origin <branch-name>

... which is equivalent to git push origin <branch-name>:<branch-name>.

... 相当于git push origin <branch-name>:<branch-name>.

So, in full, to make sure that you have merged developmentto masterlocally, and then pushed masterto GitHub, do exactly the following:

因此,要确保您已合并developmentmaster本地,然后推master送到 GitHub,请完全执行以下操作:

git checkout master
git merge development
git push origin master