git pull keeping local changes

后端 未结 6 1510
南旧
南旧 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:48

    Update: this literally answers the question asked, but I think KurzedMetal's answer is really what you want.

    Assuming that:

    1. You're on the branch master
    2. The upstream branch is master in origin
    3. You have no uncommitted changes

    .... you could do:

    # Do a pull as usual, but don't commit the result:
    git pull --no-commit
    
    # Overwrite config/config.php with the version that was there before the merge
    # and also stage that version:
    git checkout HEAD config/config.php
    
    # Create the commit:
    git commit -F .git/MERGE_MSG
    

    You could create an alias for that if you need to do it frequently. Note that if you have uncommitted changes to config/config.php, this would throw them away.

提交回复
热议问题