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

Re: git reset --hard not removing some files

From
Sean <seanlkml@sympatico.ca>
Date
Jun 2, 2006, 10:08 UTC
Message-ID
<BAYC1-PASMTP11DBD87560470F1DA42426AE910@CEZ.ICE>
In-Reply-To
<20060602093736.GL14325@admingilde.org>

On Fri, 2 Jun 2006 11:37:36 +0200 Martin Waitz <tali@admingilde.org> wrote:

Hi Martin,
> GIT reset seems to have a problem when a file is tracked and ignored
> at the same time.
I tried to reproduce this problem, but couldn't.
Show 19 quoted lines
> This fails:
> 
> diff --git a/t/t7101-reset.sh b/t/t7101-reset.sh
> index a919140..865e0f6 100755
> --- a/t/t7101-reset.sh
> +++ b/t/t7101-reset.sh
> @@ -21,10 +21,12 @@ test_expect_success \
>       cp ../../COPYING path1/COPYING &&
>       cp ../../COPYING COPYING &&
>       cp ../../COPYING path0/COPYING-TOO &&
> +     echo COPYING > .gitignore &&
>       git-add path1/path2/COPYING &&
>       git-add path1/COPYING &&
>       git-add COPYING &&
>       git-add path0/COPYING-TOO &&
> +     git-add .gitignore &&
>       git-commit -m change -a'
> 
>  test_expect_success \
This fails because git-add refuses to mark an ignored file as tracked.
So in your altered test above the COPYING file is never tracked.
git-reset then does the proper thing and refuses to remove it.  So it's
still not demonstrating the case you mention below.
 
Show 5 quoted lines
> This hit me as the Linux kernel .gitignore includes ".*" which matches
> all the .gitignore files and so they are not removed when you go
> back to 2.6.13.  But with the new git checks regarding files in
> the working dir, git then refuses to pull in newer Linux versions
> because it would overwrite ".gitignore".

Strange.. this little test shows that tracked files that are ignored do get removed when resetting --hard...

$ mkdir tryit ; cd tryit $ git init-db defaulting to local storage area

$ touch one ; git add one $ git commit -a -m"Initial" Committing initial tree 5fcffbd6e4c5c5b8d81f5e9314b20e338e3ffff5

$ touch .gitignore $ git add .gitignore $ git commit -a -m"now we have gitignore"

$ echo '.*' >> .gitignore $ git commit -a -m'now git ignores all .* files'

$ ls -l .gitignore -rw-r--r-- 1 sean sean 3 Jun 2 06:01 .gitignore

$ git reset --hard master~2 $ ls -l .gitignore ls: .gitignore: No such file or directory

Sean
Previous: Martin WaitzNext: Junio C Hamano
Message 8 of 14 in “git reset --hard not removing some files”
  1. Martin WaitzJun 1, 2006
  2. SeanJun 1, 2006
  3. Jakub NarebskiJun 1, 2006
  4. SeanJun 1, 2006
  5. Jakub NarebskiJun 2, 2006
  6. Linus TorvaldsJun 1, 2006
  7. Martin WaitzJun 2, 2006
  8. SeanJun 2, 2006
  9. Junio C HamanoJun 2, 2006
  10. Junio C HamanoJun 3, 2006
  11. Linus TorvaldsJun 3, 2006
  12. Martin WaitzJun 4, 2006
  13. Junio C HamanoJun 4, 2006
  14. Martin WaitzJun 2, 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.