Git: how to use stash -p to stash specific files?

后端 未结 3 1589
刺人心
刺人心 2021-02-01 08:47

I\'m trying to figure out how to stash two specific files among many uncommitted changes.

This very promising answer, Stash only one file out of multiple files that ha

3条回答
  •  终归单人心
    2021-02-01 09:13

    In the most recent versions of Git (> v2.13) you can stage the specific files you want to stash using

    git stash push -- 
    

    For example, if you stage the specific files you want to stash you can use this command to specifically stash only those file(s):

    git stash push -- example/file/path/and/file.html
    

    You can save yourself some typing by using a globbing pattern to stash the specific files in the path

    git stash push -- **/path/**
    

    You'll want to stage only the files you want to stash since any other staged files will be stashed with the specific files, but also remain staged after stashing so if you git stash pop you would get conflicts.

提交回复
热议问题