How can I store a particular file? [repeat]

This translation from: How the I CAN git stash A specific File [Duplicate]?

Possible Duplicate: possible repeat:
How to stash only One File OUT of Multiple Files that have have changed how to store only one file from multiple files that have changed in

How can I stash a specific file leaving the others currently modified out of the stash I am about to save? How to save a particular file, save the current modified other files in the storage area I want to save in?

For example, if git status gives me this: For example, if you give me this git status:

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? I just want to hide app / views / cart / welcome.thtml, how can I do? Something like (but of course this does not work): a bit like (but of course this does not work):

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

#1st Floor

Reference: https://stackoom.com/question/N6Rv/ How can I store a particular file - repeat


#2nd Floor

I usually add to index changes I do not want to stash and then stash with --keep-index option. I usually add an index change, I do not want to hide, then use --keep-index options are stored.

git add app/controllers/cart_controller.php
git stash --keep-index
git reset

Last step is optional, but usually you want it. The last step is optional, but usually you want it. It removes changes from index. It removes the changes from the index.


Warning of As Noted in at The Comments, Everything INTO the this the puts at The stash, both-staged and unstaged. Warning As stated in a review, which will put everything in storage, whether or not the temporary staging. The --keep-index just leaves the index alone after the stash is done. After saving is complete, - keep-index to retain only the index. This can cause merge conflicts when you later pop the stash. After a pop-up store, which may cause merge conflicts.


#3rd floor

The EDIT: Since git 2.13, there IS A to Save Command The stash A specific path to: git stash push <path>. Editor: From the beginning git 2.13, there is a command to save the specific path stored: git stash push <path>. For example: For example:

git stash push -m welcome_cart app/views/cart/welcome.thtml

OLD ANSWER: old answer:

A using CAN do that by You git stash --patch(or git stash -p) -. You'll Interactive the Enter the MODE the WHERE you'll BE presented with the each Hunk WAS changed that you can use git stash --patch(or git stash -p) to do it - you will enter the interactive mode, where you You will see each chunk of change. The Use nto Skip at The Files that you do not want to stash, ythe when you Encounter at The One that you want to stash, and qto quit and the Leave at The Remaining hunks unstashed. Use nto skip you do not want to hide the file ywhen you meet to be hiding a, and qexit and leave the rest unstashed guy. awill stash the shown hunk and the rest of the hunks in that file. aThe hidden chunks and the rest of the guy on the display of the file.

Not the most user-friendly approach, but it gets the work done if you really need it. This is not the most user-friendly way, but if you really need it, it gets the job done.

Original articles published 0 · won praise 136 · views 830 000 +

Guess you like

Origin blog.csdn.net/xfxf996/article/details/105226981
Recommended