📜  git stash apply specific index - Shell-Bash (1)

📅  最后修改于: 2023-12-03 15:30:56.494000             🧑  作者: Mango

Git Stash Apply Specific Index

Sometimes, in Git, it becomes necessary to temporarily stash or save the changes that you have made, without committing them. The git stash command serves this purpose perfectly.

However, after you've stashed the changes, you can't always apply all of them back to your working directory. In such cases, you might want to apply only a specific stash to your working directory. For this, we use the git stash apply command, with the --index or -i option.

The --index option applies the stash changes to your working directory and your index, whereas the -i option applies only the selected changes to your working directory, giving you more control over what you want to apply.

To apply a specific stash to your working directory, first, you need to list all the available stash commands by using the git stash list command. This will list all the stashes you have saved, along with a unique identifier for each one of them.

$ git stash list
stash@{0}: WIP on master: 1234abcd Commit message
stash@{1}: WIP on master: 5678efgh Commit message

Now, to apply a specific stash, use the git stash apply command, along with the stash identifier that you want to apply, and the --index or -i option.

$ git stash apply stash@{1} --index

This command will apply the second stash from the list (in this case, stash@{1}), along with its index changes, to your working directory.

That's it! You now know how to apply a specific stash to your working directory, without affecting the other saved stashes.