我有两个分支,即master和开发在一个GitHub库。我正在做我所有的开发在开发分支显示。

git branch development
git add *
git commit -m "My initial commit message"
git push -u origin development

现在我想将开发分支上的所有更改合并到主分支中。我目前的方法是:

git checkout master 
git merge development
git push -u origin master 

请让我知道我所遵循的程序是否正确。


当前回答

如果您正在使用gerrit,那么以下命令可以完美地工作。

git checkout master
git merge --no-ff development

您可以使用默认的提交消息进行保存。确保已经生成了变更id。您可以使用下面的命令来确定。

git commit --amend

然后用下面的命令进行推送。

git push origin HEAD:refs/for/refs/heads/master

您可能会遇到如下所示的错误消息。

! [remote rejected] HEAD -> refs/for/refs/heads/master (you are not allowed to upload merges)

为了解决这个问题,gerrit项目管理员必须在gerrit中创建另一个引用,命名为'refs/for/refs/heads/master'或'refs/for/refs/heads/*'(这将覆盖所有 未来的分支)。然后授予该引用的“Push Merge Commit”权限,如果需要提交GCR,则授予“Submit”权限。

现在,再次尝试上面的push命令,它应该可以工作。

学分:

https://github.com/ReviewAssistant/reviewassistant/wiki/Merging-branches-in-Gerrit

https://stackoverflow.com/a/21199818/3877642

其他回答

一旦你“签出”了开发分支,你……

 git add .
 git commit -m "first commit"
 git push origin dev
 git merge master

 git checkout master 
 git merge dev
 git push origin master 

就我个人而言,我的方法与您的类似,在提交返回到master时增加一些分支和一些压缩。

我的一个同事不喜欢如此频繁地切换分支,而是停留在开发分支上,并从开发分支执行类似于以下内容的内容。

git fetch origin master    
git merge master    
git push origin development:master

第一行确保他拥有自上次更新本地存储库以来提交给master的所有上游提交。

第二步将这些更改(如果有的话)从master导入到开发中

第三个将开发分支(现在与master完全合并)推到origin/master。

我可能把他的基本工作流程搞错了,但这是它的主要要点。

1)在分支开发上,使用以下命令检查git状态:

git status

不应该有未提交的代码。如果是,将你的代码推到开发分支:

git add *

git commit -m "My initial commit message"

git push origin Development

2)在Development分支中,运行以下两条命令:

git branch -f master HEAD

git push -f origin master

它将把您的开发分支代码推到主分支。

我认为最简单的解决办法是

git checkout master
git remote update
git merge origin/Develop -X theirs
git commit -m commit -m "New release"
git push --recurse-submodules=check --progress "origin" refs/heads/Master

这也保存了所有正在使用的分支的历史

1. //push the latest changes of current development branch if any        
git push (current development branch)

2. //switch to master branch
git checkout master 

3. //pull all the changes if any from (current development branch)
git pull origin (current development branch)

4. //Now merge development into master    
git merge development

5. //push the master branch
git push origin master

Error
To https://github.com/rajputankit22/todos-posts.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/rajputankit22/todos-posts.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

Then Use 
5. //push the master branch forcefully
git push -f origin master