乐闻世界logo
搜索文章和话题

How can i git stash a specific file?

2个答案

1
2

Typically, add the changes you don't want to hide to the index, then use the --keep-index option to hide them.

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

The last step is optional but usually necessary. It removes the changes from the index.

Warning git stash --keep-index pushes all changes to the stash, including both staged and unstaged changes. After the stash is created, only the index remains. When you later pop the stash, this may result in merge conflicts.

2024年6月29日 12:07 回复

For stashing a single file: git stash -- filename.txt

To provide a message directly in the command instead of at the prompt, add -m before the file arguments, for example: git stash -m "stash-message" -- filename1.txt

For stashing multiple files: git stash -m "stash-message" -- filename1.txt filename2.txt...

2024年6月29日 12:07 回复

你的答案