Skip to content

Commit 7aa5d43

Browse files
hashplinggitster
authored andcommitted
stash: Don't overwrite files that have gone from the index
The use of git add -u in create_stash isn't always complete. In particular, if a file has been removed from the index but changed in the work tree it will not be added to the stash's saved work tree tree object. When stash then resets the work tree to match HEAD, any changes will be lost. To be complete, any work tree file which differs from HEAD needs to be saved, regardless of whether it still appears in the index or not. This is achieved with a combination of a diff against HEAD and a call to update-index with an explicit list of paths that have changed. Signed-off-by: Charles Bailey <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 53b3c47 commit 7aa5d43

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

git-stash.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ create_stash () {
8686
GIT_INDEX_FILE="$TMP-index" &&
8787
export GIT_INDEX_FILE &&
8888
git read-tree -m $i_tree &&
89-
git add -u &&
89+
git diff --name-only -z HEAD | git update-index -z --add --remove --stdin &&
9090
git write-tree &&
9191
rm -f "$TMP-index"
9292
) ) ||

0 commit comments

Comments
 (0)