Skip to content

Commit c1ebd90

Browse files
committed
Revert "git stash: avoid data loss when "git stash save" kills a directory"
This reverts commit a736531, as it has been reported that "ls-files --killed" is too time-consuming in a deep directory with too many untracked crufts (e.g. $HOME/.git tracking only a few files). We'd need to revisit it later but "ls-files --killed" needs to be optimized before it happens.
1 parent 425df88 commit c1ebd90

File tree

3 files changed

+2
-40
lines changed

3 files changed

+2
-40
lines changed

Documentation/git-stash.txt

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ SYNOPSIS
1414
'git stash' ( pop | apply ) [--index] [-q|--quiet] [<stash>]
1515
'git stash' branch <branchname> [<stash>]
1616
'git stash' [save [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]
17-
[-u|--include-untracked] [-a|--all] [-f|--force]
18-
[<message>]]
17+
[-u|--include-untracked] [-a|--all] [<message>]]
1918
'git stash' clear
2019
'git stash' create [<message>]
2120
'git stash' store [-m|--message <message>] [-q|--quiet] <commit>
@@ -45,7 +44,7 @@ is also possible).
4544
OPTIONS
4645
-------
4746

48-
save [-p|--patch] [--[no-]keep-index] [-u|--include-untracked] [-a|--all] [-q|--quiet] [-f|--force] [<message>]::
47+
save [-p|--patch] [--[no-]keep-index] [-u|--include-untracked] [-a|--all] [-q|--quiet] [<message>]::
4948

5049
Save your local modifications to a new 'stash', and run `git reset
5150
--hard` to revert them. The <message> part is optional and gives
@@ -72,13 +71,6 @@ linkgit:git-add[1] to learn how to operate the `--patch` mode.
7271
+
7372
The `--patch` option implies `--keep-index`. You can use
7473
`--no-keep-index` to override this.
75-
+
76-
In some cases, saving a stash could mean irretrievably removing some
77-
data - if a directory with untracked files replaces a tracked file of
78-
the same name, the new untracked files are not saved (except in case
79-
of `--include-untracked`) but the original tracked file shall be restored.
80-
By default, `stash save` will abort in such a case; `--force` will allow
81-
it to remove the untracked files.
8274

8375
list [<options>]::
8476

git-stash.sh

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ save_stash () {
195195
keep_index=
196196
patch_mode=
197197
untracked=
198-
force=
199198
while test $# != 0
200199
do
201200
case "$1" in
@@ -216,9 +215,6 @@ save_stash () {
216215
-u|--include-untracked)
217216
untracked=untracked
218217
;;
219-
-f|--force)
220-
force=t
221-
;;
222218
-a|--all)
223219
untracked=all
224220
;;
@@ -262,14 +258,6 @@ save_stash () {
262258
say "$(gettext "No local changes to save")"
263259
exit 0
264260
fi
265-
if test -z "$untracked$force" &&
266-
test -n "$(git ls-files --killed | head -n 1)"
267-
then
268-
say "$(gettext "The following untracked files would NOT be saved but need to be removed by stash save:")"
269-
test -n "$GIT_QUIET" || git ls-files --killed | sed 's/^/\t/'
270-
say "$(gettext "Aborting. Consider using either the --force or --include-untracked option.")" >&2
271-
exit 1
272-
fi
273261
test -f "$GIT_DIR/logs/$ref_stash" ||
274262
clear_stash || die "$(gettext "Cannot initialize stash")"
275263

t/t3903-stash.sh

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -673,22 +673,4 @@ test_expect_success 'store updates stash ref and reflog' '
673673
grep quux bazzy
674674
'
675675

676-
test_expect_success 'stash a change to turn a non-directory to a directory' '
677-
git reset --hard &&
678-
>testfile &&
679-
git add testfile &&
680-
git commit -m "add testfile as a regular file" &&
681-
rm testfile &&
682-
mkdir testfile &&
683-
>testfile/file &&
684-
test_must_fail git stash save "recover regular file" &&
685-
test -f testfile/file
686-
'
687-
688-
test_expect_success 'stash a change to turn a non-directory to a directory (forced)' '
689-
git stash save --force "recover regular file (forced)" &&
690-
! test -f testfile/file &&
691-
test -f testfile
692-
'
693-
694676
test_done

0 commit comments

Comments
 (0)