Git checkout and merge without touching working tree

后端 未结 4 2035
面向向阳花
面向向阳花 2020-11-30 00:43

Say I have a feature branch, into which I merge upstream changes prior to pushing my changes back:

git branch feature1
... [edit my code]
... [commit]
git fe         


        
4条回答
  •  無奈伤痛
    2020-11-30 01:11

    A simple and safe way to do this—without a push or a forced update—is to fetch feature1 into master:

    (feature1)$ git fetch . feature1:master
    From .
       4a6000d..8675309  feature1   -> master
    

    The trick is using . to get the local feature1 ref. This is safer than forcibly updating the master branch, since it ensures the update is a fast-forward. (See the parameter in the git-fetch documentation for details.)

    Now that feature1 and master are the same, switching between them will not touch any files:

    (feature1)$ git checkout master
    Switched to branch 'master'
    (master)$
    

提交回复
热议问题