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

Re: [Request] Git reset should be able to ignore file permissions

From
Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Date
Jun 18, 2013, 14:06 UTC
Message-ID
<vpq7ghrqzrv.fsf@anie.imag.fr>
In-Reply-To
<CACuz9s1KGKsL-pGftAtAWyX5gUA5c-PYyJUSstf+xw151rZLtA@mail.gmail.com>
Alexander Nestorov <alexandernst@gmail.com> writes:
> I'm not trying to ignore the x bit, what I'm trying to do is make
> "git reset" checkout only the files that actually changed instead
> of checking out all the files with different permissions than the
> ones git thinks they should have.

Ah, OK, you want "git reset --hard" to just do a chmod, which would not touch the file's mtime (but only the ctime).

Then, it's even easier to demonstrate: just "touch" instead of chmod. Indeed:

$ touch myfile; sleep 2 $ strace -f git reset --hard 2>&1 | grep myfile lstat("myfile", {st_mode=S_IFREG|0755, st_size=5, ...}) = 0 lstat("myfile", {st_mode=S_IFREG|0755, st_size=5, ...}) = 0 unlink("myfile") = 0 open("myfile", O_WRONLY|O_CREAT|O_EXCL, 0777) = 4

(sleep 2 is needed in the demonstration to avoid the "racy git" safeties, but it's not really important)

Git doesn't even try to read the file content: once it detected that the stat information changed, it rewrite the file without looking at its content. It's faster this way for files that actually changed.

> Said with other word: when you run "git reset", git does a "status"
> and checkouts all the files that showed up from the "status".

No, it's indeed the opposite: "status" re-checks the content of changed files, and update the stat-cache in the index accordingly if the content actually didn't change.

Runing "git status" before "git reset --hard" should solve your problem. The part of "git status" of interest is "git update-index --refresh":

$ touch myfile; sleep 2 $ git update-index --refresh $ strace -f git reset --hard 2>&1 | grep myfile lstat("myfile", {st_mode=S_IFREG|0755, st_size=5, ...}) = 0 $

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/
Previous: Alexander NestorovNext: Alexander Nestorov
Message 4 of 18 in “[Request] Git reset should be able to ignore file permissions”
  1. Alexander NestorovJun 18, 2013
  2. Matthieu MoyJun 18, 2013
  3. Alexander NestorovJun 18, 2013
  4. Matthieu MoyJun 18, 2013
  5. Alexander NestorovJun 18, 2013
  6. Matthieu MoyJun 18, 2013
  7. Alexander NestorovJun 18, 2013
  8. Alexander NestorovJun 18, 2013
  9. Matthieu MoyJun 18, 2013
  10. Alexander NestorovJun 18, 2013
  11. Matthieu MoyJun 19, 2013
  12. Alexander NestorovJun 19, 2013
  13. Matthieu MoyJun 19, 2013
  14. Junio C HamanoJun 19, 2013
  15. Alexander NestorovJun 20, 2013
  16. Hilco WijbengaJun 19, 2013
  17. John KeepingJun 18, 2013
  18. Alexander NestorovJun 18, 2013

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.