git pull keeping local changes

后端 未结 6 1515
南旧
南旧 2020-11-30 17:14

How can I safely update (pull) a git project, keeping specific files untouched, even if there\'s upstream changes?

myrepo/config/config.php

Is there a way, o

6条回答
  •  北荒
    北荒 (楼主)
    2020-11-30 17:47

    There is a simple solution based on Git stash. Stash everything that you've changed, pull all the new stuff, apply your stash.

    git stash
    git pull
    git stash pop
    

    On stash pop there may be conflicts. In the case you describe there would in fact be a conflict for config.php. But, resolving the conflict is easy because you know that what you put in the stash is what you want. So do this:

    git checkout --theirs -- config.php
    

提交回复
热议问题