Gitlab merge request from forked repository remote through command line not creating any merge commits

不羁岁月 提交于 2019-12-11 17:38:31

问题


I am trying to merge a merge request (Gitlab) from command line.

After working on a dummy repository, I came to know that if I have the permission to merge a merge request, I can merge them directly through command line.

I started by cloning the upstream repository in my local system. After that, I made a change in my forked repository and created a merge request for the same.

While manually trying to merge the request from command line using this approach, I am getting an extra commit which is a merge commit(--no-ff).

git fetch <Fork_Repo_URL> <Fork_Repo_Branch>
git checkout -b <Branch_Name> FETCH_HEAD

git fetch origin
git checkout origin/master
git merge --no-ff <Remote_Name>-<Branch_Name>

git push origin master   

Note: The above commands are used from the cloned upstream repository.

Now, I want to do the same without cloning the upstream repository and rather by just adding an upstream remote to my forked repository.

I followed all the steps mentioned in gitlab docs for merging the request manually, but to my surprise, I am unable to see any merge commit, although the merge request is merged after using those commands.

git remote add central <Central_Repo_URL>

git fetch origin master
git checkout -b my_master FETCH_HEAD

git fetch central
git checkout central/master
git merge --no-ff my_master-master

git push central master

So, is there any way to merge a merge request by configuring a remote in forked repository(I have permission), and generate a merge commit as well?

I tried this way as well.

git fetch central
git checkout central/master
git merge --no-ff origin/master

git push central master

I have also tried commit amend, rebase.


回答1:


I have found the solution from torek's comment above. Actually by doing

git checkout central/master

I am going to a detached HEAD, all commits in this mode are lost when I exit the node.

So the best solution should be to create a local branch which can track that upstream remote named central/master.(Please ignore my branch name)

git checkout -b centralMaster central/master

Now after doing all the above steps, we can easily solve this issue, and a no fast forward merge commit as well.

git checkout -b centralMaster central/master
git fetch central
git fetch origin
git merge origin/falcondev --no-ff -m "<Message>"
git push central centralMaster:master

Now all the above problems can be easily solved.

Please comment if I had made any mistake on these steps.



来源:https://stackoverflow.com/questions/58890831/gitlab-merge-request-from-forked-repository-remote-through-command-line-not-crea

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!