Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (29.3k points)

Is there a way I can stash just my staged changes? The scenario I'm having issues with is when I've worked on several bugs at a given time, and have several unstaged changes. I'd like to be able to stage these files individually, create my .patch files, and stash them away until the code is approved. This way, when it's approved I can stash my entire (current) session, pop that bug and push the code.

Am I going about this the wrong way? Am I misunderstanding how git can work in other ways to simplify my process?

2 Answers

0 votes
by (50.2k points)

Stage all your files you need to stash.

Run 

git stash --keep-index

This command will create a stash with all of your changes (staged and unstaged),

 but will leave the staged changes in your working directory (still in state staged).

Run 

git stash save "good stash"

Now your "good stash" has only staged files.

Now if you need unstaged files before stash,

 simply apply first stash (the one created with --keep-index) and now you can remove files you stashed to "good stash".

0 votes
by (1.7k points)

Stage all of the files that you want to stash

run:

git stash --keep-index

This will create the stash, including your staged and unstaged changes, but you will still retain your staged files in the working directory.

Now you would save your good stash with:

git stash save "good stash"

If you need to apply these unstaged files before you apply the stash you can do so by running

Now, you can delete the files that were saved in the "good stash."

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...