How do I force “git pull” to overwrite local files?

前端 未结 30 3437
失恋的感觉
失恋的感觉 2020-11-21 11:35

How do I force an overwrite of local files on a git pull?

The scenario is the following:

  • A team member is modifying the t
30条回答
  •  礼貌的吻别
    2020-11-21 12:04

    I just solved this myself by:

    git checkout -b tmp # "tmp" or pick a better name for your local changes branch
    git add -A
    git commit -m 'tmp'
    git pull
    git checkout master # Or whatever branch you were on originally
    git pull
    git diff tmp
    

    where the last command gives a list of what your local changes were. Keep modifying the "tmp" branch until it is acceptable and then merge back onto master with:

    git checkout master && git merge tmp
    

    For next time, you can probably handle this in a cleaner way by looking up "git stash branch" though stash is likely to cause you trouble on the first few tries, so do first experiment on a non-critical project...

提交回复
热议问题