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

前端 未结 30 3450
失恋的感觉
失恋的感觉 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:13

    Warning, doing this will permanently delete your files if you have any directory/* entries in your gitignore file.

    Some answers seem to be terrible. Terrible in the sense of what happened to @Lauri by following David Avsajanishvili suggestion.

    Rather (git > v1.7.6):

    git stash --include-untracked
    git pull
    

    Later you can clean the stash history.

    Manually, one-by-one:

    $ git stash list
    stash@{0}: WIP on : ...
    stash@{1}: WIP on : ...
    
    $ git stash drop stash@{0}
    $ git stash drop stash@{1}
    

    Brutally, all-at-once:

    $ git stash clear
    

    Of course if you want to go back to what you stashed:

    $ git stash list
    ...
    $ git stash apply stash@{5}
    

提交回复
热议问题