git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [Request] Git reset should be able to ignore file permissions
@ 2013-06-18 13:25 Alexander Nestorov
  2013-06-18 13:34 ` Matthieu Moy
  2013-06-18 14:01 ` John Keeping
  0 siblings, 2 replies; 18+ messages in thread
From: Alexander Nestorov @ 2013-06-18 13:25 UTC (permalink / raw)
  To: git

Recently I had to write some automation scripts and I found
that git reset --hard actually restores each file's permissions.

That is causing both the created and the last-modified dates
of the file to get changed to the time of the git reset.

This behavior is easy to demonstrate:

echo "test" > myfile
chmod 777 myfile
git add myfile && git commit -m "Test" && git push
chmod 775 myfile
git reset --hard origin/master

After the git reset --hard command, the entire file was
checkout-ed. Instead, git should be able to check if the
content of the file changed and only if it did, check it out.

I do realize that checking the content of each file in a big
repo could result in a slow operation, but there should be a
switch/argument/option to make git reset actually check the
content of each file instead of blindly replacing it.

After reading man a few times I didn't saw any option
that'd let me do this; the only solution I'm able to think about
is actually restoring the permissions of each file to the ones
git thinks they should have before doing the git reset.

Maybe I'm wrong and there is a way for doing what I want, if
so, please correct me.
But if there isn't, should this be implemented? Are there any
reasons for not doing it?


Thank you for your attention
Regards

--
alexandernst

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [Request] Git reset should be able to ignore file permissions
  2013-06-18 13:25 [Request] Git reset should be able to ignore file permissions Alexander Nestorov
@ 2013-06-18 13:34 ` Matthieu Moy
  2013-06-18 13:48   ` Alexander Nestorov
  2013-06-18 14:01 ` John Keeping
  1 sibling, 1 reply; 18+ messages in thread
From: Matthieu Moy @ 2013-06-18 13:34 UTC (permalink / raw)
  To: Alexander Nestorov; +Cc: git

Alexander Nestorov <alexandernst@gmail.com> writes:

> echo "test" > myfile
> chmod 777 myfile
> git add myfile && git commit -m "Test" && git push
> chmod 775 myfile
> git reset --hard origin/master

This doesn't tell what the permissions are in origin/master.

If the last line was "git reset --hard HEAD", then it wouldn't touch
myfile (it's executable in the worktree and in HEAD, so Git doesn't need
to change it). Neither the x bit, nor the ctime or mtime.

If you reset the file to a point where it was not executable, then Git
changes its executable bit, and I don't see why it would do otherwise:
Git tracks the executable bit, so when you say "reset the file to how it
was in this revision", this includes the content and executability.

Reading your message, I don't understand why you need to be able to
ignore the x bit.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [Request] Git reset should be able to ignore file permissions
  2013-06-18 13:34 ` Matthieu Moy
@ 2013-06-18 13:48   ` Alexander Nestorov
  2013-06-18 14:06     ` Matthieu Moy
  0 siblings, 1 reply; 18+ messages in thread
From: Alexander Nestorov @ 2013-06-18 13:48 UTC (permalink / raw)
  To: git

Git does preserve file permissions, that is, git is aware of the
permissions you can set with chmod.

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.

Said with other word: when you run "git reset", git does a "status"
and checkouts all the files that showed up from the "status".
That's exactly what I'm trying to avoid, as "status" is aware of both
content changes and permissions changes.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [Request] Git reset should be able to ignore file permissions
  2013-06-18 13:25 [Request] Git reset should be able to ignore file permissions Alexander Nestorov
  2013-06-18 13:34 ` Matthieu Moy
@ 2013-06-18 14:01 ` John Keeping
  2013-06-18 14:05   ` Alexander Nestorov
  1 sibling, 1 reply; 18+ messages in thread
From: John Keeping @ 2013-06-18 14:01 UTC (permalink / raw)
  To: Alexander Nestorov; +Cc: git

On Tue, Jun 18, 2013 at 03:25:22PM +0200, Alexander Nestorov wrote:
> Recently I had to write some automation scripts and I found
> that git reset --hard actually restores each file's permissions.
> 
> That is causing both the created and the last-modified dates
> of the file to get changed to the time of the git reset.
> 
> This behavior is easy to demonstrate:
> 
> echo "test" > myfile
> chmod 777 myfile
> git add myfile && git commit -m "Test" && git push
> chmod 775 myfile
> git reset --hard origin/master
> 
> After the git reset --hard command, the entire file was
> checkout-ed. Instead, git should be able to check if the
> content of the file changed and only if it did, check it out.

Does "git reset --keep" behave in the same way?  I would expect it to
leave permissions as they were.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [Request] Git reset should be able to ignore file permissions
  2013-06-18 14:01 ` John Keeping
@ 2013-06-18 14:05   ` Alexander Nestorov
  0 siblings, 0 replies; 18+ messages in thread
From: Alexander Nestorov @ 2013-06-18 14:05 UTC (permalink / raw)
  To: git

Git reset --keep is not an option as it will abort the operation if
there are local changes,
which is exactly what I want to do: replace files with local changes
but leave file
permissions as they are.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [Request] Git reset should be able to ignore file permissions
  2013-06-18 13:48   ` Alexander Nestorov
@ 2013-06-18 14:06     ` Matthieu Moy
  2013-06-18 14:22       ` Alexander Nestorov
  0 siblings, 1 reply; 18+ messages in thread
From: Matthieu Moy @ 2013-06-18 14:06 UTC (permalink / raw)
  To: Alexander Nestorov; +Cc: git

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/

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [Request] Git reset should be able to ignore file permissions
  2013-06-18 14:06     ` Matthieu Moy
@ 2013-06-18 14:22       ` Alexander Nestorov
  2013-06-18 14:33         ` Matthieu Moy
  0 siblings, 1 reply; 18+ messages in thread
From: Alexander Nestorov @ 2013-06-18 14:22 UTC (permalink / raw)
  To: git

Indeed, "git update-index --refresh" before "git reset" did the trick :)
Anyways, what about the proposal? Should it be implemented?

Thank you

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [Request] Git reset should be able to ignore file permissions
  2013-06-18 14:22       ` Alexander Nestorov
@ 2013-06-18 14:33         ` Matthieu Moy
  2013-06-18 14:39           ` Alexander Nestorov
  0 siblings, 1 reply; 18+ messages in thread
From: Matthieu Moy @ 2013-06-18 14:33 UTC (permalink / raw)
  To: Alexander Nestorov; +Cc: git

[ The rule here is to keep everyone Cced, not just git@vger ]

Alexander Nestorov <alexandernst@gmail.com> writes:

> Indeed, "git update-index --refresh" before "git reset" did the trick :)
> Anyways, what about the proposal? Should it be implemented?

I'd say the current behavior is OK by default (it's not so common to
have stat-only changes, and re-checking the content would slow down the
other operations).

We could add a flag to "git reset" asking it to refresh the index before
continuing, but that would essentially end-up doing "git update-index
--refresh; git reset".

It would make more sense to me to add something about update-index in
the documentation of git reset. Patches welcome ;-).

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [Request] Git reset should be able to ignore file permissions
  2013-06-18 14:33         ` Matthieu Moy
@ 2013-06-18 14:39           ` Alexander Nestorov
  2013-06-18 15:51             ` Alexander Nestorov
  0 siblings, 1 reply; 18+ messages in thread
From: Alexander Nestorov @ 2013-06-18 14:39 UTC (permalink / raw)
  To: Matthieu Moy; +Cc: git

Sorry for not keeping everyone Cced, I wasn't aware of the rules.

Yes, writing about that in the docs seems more reasonable than patching reset,
as as you said, that'd just run update-index before the reset.
Let me get at home and I'll try to push a change :)

Regards

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [Request] Git reset should be able to ignore file permissions
  2013-06-18 14:39           ` Alexander Nestorov
@ 2013-06-18 15:51             ` Alexander Nestorov
  2013-06-18 16:00               ` Matthieu Moy
  0 siblings, 1 reply; 18+ messages in thread
From: Alexander Nestorov @ 2013-06-18 15:51 UTC (permalink / raw)
  To: Matthieu Moy; +Cc: git

I'm home, https://github.com/alexandernst/git/commit/61f0a7d558e3cbae308fabdff66bd87569d6aa18
Is that good? Should I PR?

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [Request] Git reset should be able to ignore file permissions
  2013-06-18 15:51             ` Alexander Nestorov
@ 2013-06-18 16:00               ` Matthieu Moy
  2013-06-18 17:03                 ` Alexander Nestorov
  0 siblings, 1 reply; 18+ messages in thread
From: Matthieu Moy @ 2013-06-18 16:00 UTC (permalink / raw)
  To: Alexander Nestorov; +Cc: git

Alexander Nestorov <alexandernst@gmail.com> writes:

> I'm home, https://github.com/alexandernst/git/commit/61f0a7d558e3cbae308fabdff66bd87569d6aa18
> Is that good?

Please, post your patches inline, it eases review. More generally, read
Documentation/SubmittingPatches.

+Ignore file permissions::

It's not only about permissions, and it does not "ignore" them, it just
notices when there's actually no change although the mtime has changed.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [Request] Git reset should be able to ignore file permissions
  2013-06-18 16:00               ` Matthieu Moy
@ 2013-06-18 17:03                 ` Alexander Nestorov
  2013-06-19  5:40                   ` Matthieu Moy
  0 siblings, 1 reply; 18+ messages in thread
From: Alexander Nestorov @ 2013-06-18 17:03 UTC (permalink / raw)
  To: Matthieu Moy; +Cc: git

How about that:

+Reset only files who's content changed (instead of mtime modification)::
++
+------------
+$ git update-index --refresh               <1>
+$ git reset --hard                         <2>
+------------
++
+<1> Make git realize which files actually changed instead of
+checking out all files whether their content changed or only
+their mtime changed.
+<2> Now git reset --hard will checkout only the files that
+actually changed.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [Request] Git reset should be able to ignore file permissions
  2013-06-18 17:03                 ` Alexander Nestorov
@ 2013-06-19  5:40                   ` Matthieu Moy
  2013-06-19  8:00                     ` Alexander Nestorov
  0 siblings, 1 reply; 18+ messages in thread
From: Matthieu Moy @ 2013-06-19  5:40 UTC (permalink / raw)
  To: Alexander Nestorov; +Cc: git

Alexander Nestorov <alexandernst@gmail.com> writes:

> How about that:
>
> +Reset only files who's content changed (instead of mtime modification)::

Much better, yes. I'd say "stat information" instead of mtime (that's
what used in the description of update-index --refresh, and is a bit
more accurate since Git also checks the inode number IIRC).

> +------------
> +$ git update-index --refresh               <1>
> +$ git reset --hard                         <2>
> +------------
> ++
> +<1> Make git realize which files actually changed instead of

s/git/Git/ when talking about "The Git system" (as opposed to "The git
command"). git-gui or other Git clients would also see the index change.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [Request] Git reset should be able to ignore file permissions
  2013-06-19  5:40                   ` Matthieu Moy
@ 2013-06-19  8:00                     ` Alexander Nestorov
  2013-06-19 11:37                       ` Matthieu Moy
  2013-06-19 16:40                       ` Hilco Wijbenga
  0 siblings, 2 replies; 18+ messages in thread
From: Alexander Nestorov @ 2013-06-19  8:00 UTC (permalink / raw)
  To: Matthieu Moy; +Cc: git

Ok, this is how it looks. If everything is ok, I'm sending it to the ML

>From 262bdfb5cc84fec7c9b74dc92bb604f9d168ef9a Mon Sep 17 00:00:00 2001
From: Alexander Nestorov <alexandernst@gmail.com>
Date: Wed, 19 Jun 2013 09:55:42 +0200
Subject: [PATCH] Add example for reseting based on content changes instead of
 stat changes

---
 Documentation/git-reset.txt | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/Documentation/git-reset.txt b/Documentation/git-reset.txt
index a404b47..da639e9 100644
--- a/Documentation/git-reset.txt
+++ b/Documentation/git-reset.txt
@@ -289,6 +289,18 @@ $ git reset --keep start                    <3>
 <3> But you can use "reset --keep" to remove the unwanted commit after
     you switched to "branch2".

+Reset only files who's content changed (instead of stat information)::
++
+------------
+$ git update-index --refresh               <1>
+$ git reset --hard                         <2>
+------------
++
+<1> Make Git realize which files actually changed instead of
+checking out all files whether their content changed or only
+their mtime changed.
+<2> Now git reset --hard will checkout only the files that
+actually changed.

 DISCUSSION
 ----------
--
1.8.1.msysgit.1

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [Request] Git reset should be able to ignore file permissions
  2013-06-19  8:00                     ` Alexander Nestorov
@ 2013-06-19 11:37                       ` Matthieu Moy
  2013-06-19 18:43                         ` Junio C Hamano
  2013-06-19 16:40                       ` Hilco Wijbenga
  1 sibling, 1 reply; 18+ messages in thread
From: Matthieu Moy @ 2013-06-19 11:37 UTC (permalink / raw)
  To: Alexander Nestorov; +Cc: git

Alexander Nestorov <alexandernst@gmail.com> writes:

> Ok, this is how it looks. If everything is ok, I'm sending it to the ML

Please, read Documentation/SubmittingPatches (you lack a sign-off and if
you think the patch is ready, you should Cc Junio). Also, it's better to
have the commit headers directly as mail headers (git send-email is your
friend).

> +Reset only files who's content changed (instead of stat information)::

That's still not 100% accurate. Actual mode changes would trigger a
rewrite of the file. Perhaps stg like

Reset only files which actually changed (not those with only stat information change)::

(Sorry for nitpicking so much)

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [Request] Git reset should be able to ignore file permissions
  2013-06-19  8:00                     ` Alexander Nestorov
  2013-06-19 11:37                       ` Matthieu Moy
@ 2013-06-19 16:40                       ` Hilco Wijbenga
  1 sibling, 0 replies; 18+ messages in thread
From: Hilco Wijbenga @ 2013-06-19 16:40 UTC (permalink / raw)
  To: Alexander Nestorov; +Cc: Matthieu Moy, git

On 19 June 2013 01:00, Alexander Nestorov <alexandernst@gmail.com> wrote:
> Ok, this is how it looks. If everything is ok, I'm sending it to the ML
>
> From 262bdfb5cc84fec7c9b74dc92bb604f9d168ef9a Mon Sep 17 00:00:00 2001
> From: Alexander Nestorov <alexandernst@gmail.com>
> Date: Wed, 19 Jun 2013 09:55:42 +0200
> Subject: [PATCH] Add example for reseting based on content changes instead of
>  stat changes
>
> ---
>  Documentation/git-reset.txt | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
>
> diff --git a/Documentation/git-reset.txt b/Documentation/git-reset.txt
> index a404b47..da639e9 100644
> --- a/Documentation/git-reset.txt
> +++ b/Documentation/git-reset.txt
> @@ -289,6 +289,18 @@ $ git reset --keep start                    <3>
>  <3> But you can use "reset --keep" to remove the unwanted commit after
>      you switched to "branch2".
>
> +Reset only files who's content changed (instead of stat information)::

You should use "whose" here instead of "who's".

> ++
> +------------
> +$ git update-index --refresh               <1>
> +$ git reset --hard                         <2>
> +------------
> ++
> +<1> Make Git realize which files actually changed instead of
> +checking out all files whether their content changed or only
> +their mtime changed.
> +<2> Now git reset --hard will checkout only the files that
> +actually changed.
>
>  DISCUSSION
>  ----------
> --
> 1.8.1.msysgit.1
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [Request] Git reset should be able to ignore file permissions
  2013-06-19 11:37                       ` Matthieu Moy
@ 2013-06-19 18:43                         ` Junio C Hamano
  2013-06-20 13:28                           ` Alexander Nestorov
  0 siblings, 1 reply; 18+ messages in thread
From: Junio C Hamano @ 2013-06-19 18:43 UTC (permalink / raw)
  To: Matthieu Moy; +Cc: Alexander Nestorov, git

Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes:

> Alexander Nestorov <alexandernst@gmail.com> writes:
>
>> Ok, this is how it looks. If everything is ok, I'm sending it to the ML
>
> Please, read Documentation/SubmittingPatches (you lack a sign-off and if
> you think the patch is ready, you should Cc Junio). Also, it's better to
> have the commit headers directly as mail headers (git send-email is your
> friend).
>
>> +Reset only files who's content changed (instead of stat information)::
>
> That's still not 100% accurate. Actual mode changes would trigger a
> rewrite of the file. Perhaps stg like
>
> Reset only files which actually changed (not those with only stat information change)::
>
> (Sorry for nitpicking so much)

I do not think the above clarifies anything to be of much help.

If you _know_ what "actually changed" means, i.e. either contents or
the executable-ness changed, then "(not those ...)" does not help
you at all.

If you don't, then "only stat information change" will invite "I did
chmod -x and the file does not have any actual change." confusion.

If this addition is to help people who do not know what "actually
changed" means, that part needs to be clarified, no?

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [Request] Git reset should be able to ignore file permissions
  2013-06-19 18:43                         ` Junio C Hamano
@ 2013-06-20 13:28                           ` Alexander Nestorov
  0 siblings, 0 replies; 18+ messages in thread
From: Alexander Nestorov @ 2013-06-20 13:28 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Matthieu Moy, git

@Matthieu
 Ok, I'm replacing with "Reset only files which actually changed (not
those with only stat information change)"

@Junio
 I'm not sure what you're asking, sorry, I'm not able to understand
your question.

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2013-06-20 13:29 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-18 13:25 [Request] Git reset should be able to ignore file permissions Alexander Nestorov
2013-06-18 13:34 ` Matthieu Moy
2013-06-18 13:48   ` Alexander Nestorov
2013-06-18 14:06     ` Matthieu Moy
2013-06-18 14:22       ` Alexander Nestorov
2013-06-18 14:33         ` Matthieu Moy
2013-06-18 14:39           ` Alexander Nestorov
2013-06-18 15:51             ` Alexander Nestorov
2013-06-18 16:00               ` Matthieu Moy
2013-06-18 17:03                 ` Alexander Nestorov
2013-06-19  5:40                   ` Matthieu Moy
2013-06-19  8:00                     ` Alexander Nestorov
2013-06-19 11:37                       ` Matthieu Moy
2013-06-19 18:43                         ` Junio C Hamano
2013-06-20 13:28                           ` Alexander Nestorov
2013-06-19 16:40                       ` Hilco Wijbenga
2013-06-18 14:01 ` John Keeping
2013-06-18 14:05   ` Alexander Nestorov

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).