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

git checkout -f branch doesn't remove extra files

From
Luck, Tony <tony.luck@intel.com>
Date
Aug 12, 2005, 17:31 UTC
Message-ID
<B8E391BBE9FE384DAA4C5C003888BE6F04214AC7@scsmsx401.amr.corp.intel.com>

I've just got around to noticing some of the new (to me) features in git, and started experimenting with branches.

I see that when I switch view to a different branch with:

	$ git checkout -f someoldbranch

that any files that exist in my previous branch view but not in "someoldbranch" are not deleted. I can find and remove them easily with:

	$ git-ls-files --others | xargs rm -f

but I wondered whether this was a deliberate choice (to avoid clobbering .o files etc. for people who have run a make in their tree).

Currently git-ls-files doesn't have a way to specify a branch ... but it it did, the something like:

	comm -1 <(git-ls-files -b oldbranch) \
		  <(git-ls-files -b newbranch) | xargs rm -f
would clean up the spurious files.
-Tony
Next: Junio C Hamano
Message 1 of 2 in “git checkout -f branch doesn't remove extra files”
  1. Luck, TonyAug 12, 2005
  2. Junio C HamanoAug 12, 2005

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.