Skip to content

Commit

Permalink
stash: Don't overwrite files that have gone from the index
Browse files Browse the repository at this point in the history
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 <charles@hashpling.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Charles Bailey authored and Junio C Hamano committed Apr 18, 2010
1 parent 53b3c47 commit 7aa5d43
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion git-stash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ create_stash () {
GIT_INDEX_FILE="$TMP-index" &&
export GIT_INDEX_FILE &&
git read-tree -m $i_tree &&
git add -u &&
git diff --name-only -z HEAD | git update-index -z --add --remove --stdin &&
git write-tree &&
rm -f "$TMP-index"
) ) ||
Expand Down

0 comments on commit 7aa5d43

Please sign in to comment.