git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] checkout -f: do not leave untracked working tree files.

From
Junio C Hamano <junkio@cox.net>
Date
Jun 20, 2006, 09:50 UTC
Message-ID
<7vfyi0b1gv.fsf_-_@assigned-by-dhcp.cox.net>
In-Reply-To
<7vr71kb257.fsf@assigned-by-dhcp.cox.net>

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>
---
 * I am going to bed without trying this out since it is very
   late tonight.  Might be in "pu" or "next" tomorrow depending
   on my mood.  If this works out for Jeff, I can simply drop
   the "core.oktoclobber = ask" patch from my topics -- although
   I kind of liked that one ;-).
 git-checkout.sh |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
diff --git a/git-checkout.sh b/git-checkout.sh
index 564117f..77c2593 100755
--- a/git-checkout.sh
+++ b/git-checkout.sh
@@ -137,8 +137,7 @@ # what we already had
 
 if [ "$force" ]
 then
-    git-read-tree --reset $new &&
-	git-checkout-index -q -f -u -a
+    git-read-tree --reset -u $new
 else
     git-update-index --refresh >/dev/null
     merge_error=$(git-read-tree -m -u $old $new 2>&1) || (
-- 
1.4.0.g59268
Previous: Junio C HamanoNext: Santi Béjar
Message 11 of 17 in “git 1.4.0 usability problem”
  1. Jeff GarzikJun 18, 2006
  2. Ryan AndersonJun 18, 2006
  3. Ryan AndersonJun 18, 2006
  4. Junio C HamanoJun 18, 2006
  5. Junio C HamanoJun 18, 2006
  6. Jeff GarzikJun 18, 2006
  7. Junio C HamanoJun 19, 2006
  8. Jeff GarzikJun 20, 2006
  9. Ryan AndersonJun 20, 2006
  10. Junio C HamanoJun 20, 2006
  11. checkout -f: do not leave untracked working tree files.Junio C Hamano, Jun 20, 2006
  12. Santi BéjarJun 20, 2006
  13. Junio C HamanoJun 20, 2006
  14. Alexander LitvinovJun 20, 2006
  15. Junio C HamanoJun 20, 2006
  16. Alexander LitvinovJun 20, 2006
  17. Carl WorthJun 20, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.