lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lmi] git: committing content and mode changes together


From: Vadim Zeitlin
Subject: Re: [lmi] git: committing content and mode changes together
Date: Fri, 4 Nov 2016 14:52:27 +0100

On Fri, 4 Nov 2016 01:59:36 +0000 Greg Chicares <address@hidden> wrote:

GC> Working with one particular file (in a proprietary repository),
GC> I changed its contents and its mode, thus:
GC>   git update-index --chmod=-x my_file.txt

 I hadn't known about --chmod option of update-index until today, thanks
for mentioning it, it's surely going to be useful to me in the future.

GC>   sed -i my_file.txt -e's/  //g'
GC> and then committed it
GC>   git commit my_file.txt -m'Remove tabs and executable bit'
GC> but the mode change didn't get committed.

 I think that what happens here is that the file is still executable in
your working directory and when you commit it (instead of just committing
the already staged changes, a.k.a. the index), the mode gets changed back
to "+x".

GC> Then I did a 'reset --hard', and split it into two steps:
GC> 
GC>   git update-index --chmod=-x my_file.txt
GC>   git commit my_file.txt -m'Reset executable bit'

 I can't explain this though... As I said, I don't have any experience with
it because the way I normally do it is just

        $ chmod -x my_file.txt
        $ git commit -m 'Reset executable bit' $_

GC> and that step worked, but then when I did this:
GC> 
GC>   sed -i my_file.txt -e's/  //g'
GC>   git commit my_file.txt -m'Remove tabs'
GC> 
GC> the mode change was reverted.

 This is even more mysterious, especially if this is under Linux and not
Cygwin. Under Cygwin file permissions are a never ending source of
puzzlement as Cygwin permissions don't map one to one to MSW ACLs and if
you touch the same file using a native MSW program you're almost bound to
have some surprises. It also depends on whether you use the Cygwin or
native version of git, whether your core.filemode is true or false (which I
strongly recommend) for this repository and the current phase of the moon.

 In this particular case I don't really see any explanation for the mode
change however, as "sed" is almost surely the Cygwin utility and shouldn't
do anything strange with the permissions. And if you're not under Cygwin in
the first place, then I have absolutely no idea at all as I've never had
any permissions-related problems under Unix systems (Linux, OS X or even
Solaris).

GC> but my problem is the opposite: I want to commit them together. What's
GC> the simple, obvious sequence of steps to do that?

 Committing everything together is the simplest thing to do, of course, as
there is no need to split anything, i.e. you can just use "chmod -x" and
then commit all changes together, as shown above. I have a feeling I might
be misunderstanding something here though, as if you don't need to split
the changes in several commits, why would you bother with adding them to
the index at all, instead of just committing directly? Could you please
explain what exactly is the initial state and the desired final one, i.e.
which commits would you like to make? And which platform are you doing this
under?

 Thanks in advance,
VZ


reply via email to

[Prev in Thread] Current Thread [Next in Thread]