Skip to content

Commit 4170af8

Browse files
author
Junio C Hamano
committed
checkout -f: do not leave untracked working tree files.
Earlier we did not consider untracked working tree files "precious", but we have always considered them fair game to clobber. These days, branch switching by read-tree is more careful and tries to protect untracked working tree files. This caused the following workflow to stop working: git checkout one-branch-with-file-F git checkout -f another-without-file-F git pull . one-branch-with-file-F Because the second checkout leaves F from the previous state as untracked file in the working tree, the merge would fail, trying to protect F from being clobbered. This changes "git checkout -f" to remove working tree files that are known to git in the switched-from state but do not exist in the switched-to state, borrowing the same logic from "reset --hard". Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent 5b276ee commit 4170af8

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

git-checkout.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,7 @@ fi
137137

138138
if [ "$force" ]
139139
then
140-
git-read-tree --reset $new &&
141-
git-checkout-index -q -f -u -a
140+
git-read-tree --reset -u $new
142141
else
143142
git-update-index --refresh >/dev/null
144143
merge_error=$(git-read-tree -m -u $old $new 2>&1) || (

0 commit comments

Comments
 (0)