Merge, update, and pull Git branches without using checkouts

前端 未结 17 1385
臣服心动
臣服心动 2020-11-22 07:42

I work on a project that has 2 branches, A and B. I typically work on branch A, and merge stuff from branch B. For the merging, I would typically do:

git mer         


        
17条回答
  •  北海茫月
    2020-11-22 08:30

    You can only do this if the merge is a fast-forward. If it's not, then git needs to have the files checked out so it can merge them!

    To do it for a fast-forward only:

    git fetch 
    git update-ref -m "merge : Fast forward" refs/heads/ 
    

    where is the fetched commit, the one you want to fast-forward to. This is basically like using git branch -f to move the branch, except it also records it in the reflog as if you actually did the merge.

    Please, please, please don't do this for something that's not a fast-forward, or you'll just be resetting your branch to the other commit. (To check, see if git merge-base gives the branch's SHA1.)

提交回复
热议问题