How can I git stash a specific file

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

Possible Duplicate:
http://stackoverflow.com/questions/3040833/how-to-stash-only-one-file-out-of-multiple-files-that-have-changed http://stackoverflow.com/questions/3040833/how-to-stash-only-one-file-out-of-multiple-files-that-have-changed


How can I stash a specific file leaving the others currently modified out of the stash I am about to save?

For example, if git status gives me this:

younker % gst      
# On branch master
# Your branch is ahead of  origin/master  by 1 commit.
#
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   app/controllers/cart_controller.php
#   modified:   app/views/cart/welcome.thtml
#
no changes added to commit (use "git add" and/or "git commit -a")

and I only want to stash app/views/cart/welcome.thtml, how would I do that? Something like (but of course this does not work):

git stash save welcome_cart app/views/cart/welcome.thtml

Answers

You can do that using git stash --patch (or git stash -p) -- you ll enter interactive mode where you ll be presented with each hunk that was changed. Use n to skip the files that you don t want to stash, y when you encounter the one that you want to stash, and q to quit and leave the remaining hunks unstashed.

Not the most user-friendly approach, but it gets the work done if you really need it.

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/5506339/how-can-i-git-stash-a-specific-file

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils