Make the current Git branch a master branch

前端 未结 14 2171
悲&欢浪女
悲&欢浪女 2020-11-22 05:29

I have a repository in Git. I made a branch, then did some changes both to the master and to the branch.

Then, tens of commits later, I realized the branch is in muc

14条回答
  •  爱一瞬间的悲伤
    2020-11-22 06:13

    To add to Jefromi's answer, if you don't want to place a meaningless merge in the history of the source branch, you can create a temporary branch for the ours merge, then throw it away:

    git checkout 
    git checkout -b temp            # temporary branch for merge
    git merge -s ours       # create merge commit with contents of 
    git checkout            # fast forward  to merge commit
    git merge temp                  # ...
    git branch -d temp              # throw temporary branch away
    

    That way the merge commit will only exist in the history of the target branch.

    Alternatively, if you don't want to create a merge at all, you can simply grab the contents of source and use them for a new commit on target:

    git checkout                           # fill index with contents of 
    git symbolic-ref HEAD                  # tell git we're committing on 
    git commit -m "Setting contents to "   # make an ordinary commit with the contents of 
    

提交回复
热议问题