threads / discuss / 31729

Ignore on commit

Subject: Ignore on commit

## tl;dr

12 messages between Oct 4, 2012 and Oct 5, 2012.

replies: 11people: 8as markdown or json

Marco Craveiro· Oct 4, 2012, 16:45 UTC · lore
Hello gitters,

One of the very (very) few features I miss in svn is "ignore on commit" (or, more generally, changelists). I'm not sure if this has been discussed in the past - google failed me a bit due to spurious matches - but I personally find it quite useful. The feature is described here [1] (and graphically, here [2]).

The gist of it is, one can mark certain files as "ignore on commit" and they get placed on a "special list" which shows up on status. These lists are effectively a sub-division of modified (but not staged). Up till now I have found the staging area to be quite sufficient, but recently I hit a use case where I was modifying a large number of files; some modifications were hacks required to get the build to work but were not meant to ever get checked in, most other files had real work. In cases like this its really useful to mark the hacked files as "ignore on commit", so that a) we don't lose track of them (as one would with git ignore, or with [4]) but b) we won't check them in by mistake.

I found some tips on how to survive without change lists ([3], [4]) but they are a bit more cumbersome. Has this feature been discussed?

Thanks a lot for an amazing piece of software, and thanks for your time.
Cheers
Marco
-- 
So young, and already so unknown -- Pauli

blog: http://mcraveiro.blogspot.com

[1] http://svnbook.red-bean.com/en/1.6/svn.ref.svn.c.changelist.html
[2] http://blog.baljeetsingh.net/2009/02/tips-tricks-svn-ignore-on-commit.html
[3] http://stackoverflow.com/questions/10606809/git-equivalence-of-svn-changelist
[4] http://gitready.com/intermediate/2009/02/18/temporarily-ignoring-files.html
Pascal Obry· Oct 4, 2012, 20:06 UTC · re: Marco Craveiro · lore

Re: Ignore on commit

I'm not sure to follow everything... But looks like:
   $ git add -p
or
   $ git add -i
should do what you want, no?
You select the hunks to commit, let over the "hacks" and then
   $ git commit
-- 
  Pascal Obry /  Magny Les Hameaux (78)

  The best way to travel is by means of imagination

  http://v2p.fr.eu.org
  http://www.obry.net

  gpg --keyserver keys.gnupg.net --recv-key F949BD3B
Marco Craveiro· Oct 4, 2012, 21:20 UTC · re: Pascal Obry · lore

Re: Ignore on commit

<ignore on commit>
Show 13 quoted lines
> I'm not sure to follow everything... But looks like:
>
>    $ git add -p
>
> or
>
>    $ git add -i
>
> should do what you want, no?
>
> You select the hunks to commit, let over the "hacks" and then
>
>    $ git commit

Similar but not quite; the idea is that you know that there is some code (I'm just talking about files here, so lets ignore hunks for the moment) which is normally checked in but for a period of time you want it ignored. So you don't want it git ignored but at the same time you don't want to see these files in the list of modified files. The changelist concept allows you to "move" the files out of the way from the main modified section until you are ready to commit them. Perhaps an imaginary git status would help:

# Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: some_staged_file.h # # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: some_modified_file.h # # Changes ignored on commit: # # modified: some_other_modified_file.h

Such that if you now did a git add -A, some_modified_file.h would then be staged but some_other_modified_file.h would stay put. Of course the name "ignored on commit" makes little sense in git terms, but I'm using it here as its the svn term. Its a "modified but temporarily ignored" or something.

Cheers
Marco
-- 
So young, and already so unknown -- Pauli

blog: http://mcraveiro.blogspot.com
Andrew Wong· Oct 4, 2012, 23:02 UTC · re: Marco Craveiro · lore

Re: Ignore on commit

On 10/04/2012 05:20 PM, Marco Craveiro wrote:
Show 5 quoted lines
> Similar but not quite; the idea is that you know that there is some
> code (I'm just talking about files here, so lets ignore hunks for the
> moment) which is normally checked in but for a period of time you want
> it ignored. So you don't want it git ignored but at the same time you
> don't want to see these files in the list of modified files.

The way I usually handle this scenario is by actually making a temporary commit with those temporary changes. And whenever I make a permanent commit, I'll use "rebase -i" to rearrange the commits so that all my permanent commits go before my temporary commits. So when I need to push, I'll just push up till before my temporary commits.

This way I also get to make permanent changes in files that I have temporary changes.

Andrew Ardill· Oct 5, 2012, 01:00 UTC · re: Marco Craveiro · lore

Re: Ignore on commit

On 5 October 2012 07:20, Marco Craveiro <marco.craveiro@gmail.com> wrote:
Show 6 quoted lines
> ...
> Similar but not quite; the idea is that you know that there is some
> code (I'm just talking about files here, so lets ignore hunks for the
> moment) which is normally checked in but for a period of time you want
> it ignored. So you don't want it git ignored but at the same time you
> don't want to see these files in the list of modified files.

What is the reason git ignore is no good in this case? Is it simply that you can't see the ignored files in git status, or is it that adding and removing entries to .gitignore is too cumbersome? If it's the latter you could probably put together a simple shell wrapper to automate the task, as otherwise it seems like git ignore does what you need.

Regards,
Andrew Ardill
demerphq· Oct 5, 2012, 01:35 UTC · re: Andrew Ardill · lore

Re: Ignore on commit

On 5 October 2012 03:00, Andrew Ardill <andrew.ardill@gmail.com> wrote:
Show 14 quoted lines
> On 5 October 2012 07:20, Marco Craveiro <marco.craveiro@gmail.com> wrote:
>> ...
>> Similar but not quite; the idea is that you know that there is some
>> code (I'm just talking about files here, so lets ignore hunks for the
>> moment) which is normally checked in but for a period of time you want
>> it ignored. So you don't want it git ignored but at the same time you
>> don't want to see these files in the list of modified files.
>
> What is the reason git ignore is no good in this case? Is it simply
> that you can't see the ignored files in git status, or is it that
> adding and removing entries to .gitignore is too cumbersome? If it's
> the latter you could probably put together a simple shell wrapper to
> automate the task, as otherwise it seems like git ignore does what you
> need.
Git ignore doesn't ignore tracked files.
Yves
-- 
perl -Mre=debug -e "/just|another|perl|hacker/"
Sitaram Chamarty· Oct 5, 2012, 02:20 UTC · re: demerphq · lore

Re: Ignore on commit

On Fri, Oct 5, 2012 at 7:05 AM, demerphq <demerphq@gmail.com> wrote:
Show 17 quoted lines
> On 5 October 2012 03:00, Andrew Ardill <andrew.ardill@gmail.com> wrote:
>> On 5 October 2012 07:20, Marco Craveiro <marco.craveiro@gmail.com> wrote:
>>> ...
>>> Similar but not quite; the idea is that you know that there is some
>>> code (I'm just talking about files here, so lets ignore hunks for the
>>> moment) which is normally checked in but for a period of time you want
>>> it ignored. So you don't want it git ignored but at the same time you
>>> don't want to see these files in the list of modified files.
>>
>> What is the reason git ignore is no good in this case? Is it simply
>> that you can't see the ignored files in git status, or is it that
>> adding and removing entries to .gitignore is too cumbersome? If it's
>> the latter you could probably put together a simple shell wrapper to
>> automate the task, as otherwise it seems like git ignore does what you
>> need.
>
> Git ignore doesn't ignore tracked files.

would 'git update-index --assume-unchanged' work in this case? Didn't see it mentioned in any of the replies so far (but I have never used it myself)

Junio C Hamano· Oct 5, 2012, 02:44 UTC · re: Sitaram Chamarty · lore

Re: Ignore on commit

Sitaram Chamarty <sitaramc@gmail.com> writes:
Show 5 quoted lines
>> Git ignore doesn't ignore tracked files.
>
> would 'git update-index --assume-unchanged' work in this case?  Didn't
> see it mentioned in any of the replies so far (but I have never used
> it myself)

The assume-unchanged bit is *not* an instruction to tell Git to ignore changes. It is your *promise* that you will not change it, and tells Git that it is free to use the contents from the working tree and the contents in the index interchangeably, taking whichever is more convenient for Git to handle.

So, no, it might appear to work in some cases, but you are playing with an undefined behaviour.

Andrew Ardill· Oct 5, 2012, 02:44 UTC · re: Sitaram Chamarty · lore

Re: Ignore on commit

On 5 October 2012 12:20, Sitaram Chamarty <sitaramc@gmail.com> wrote:
Show 22 quoted lines
> On Fri, Oct 5, 2012 at 7:05 AM, demerphq <demerphq@gmail.com> wrote:
>> On 5 October 2012 03:00, Andrew Ardill <andrew.ardill@gmail.com> wrote:
>>> On 5 October 2012 07:20, Marco Craveiro <marco.craveiro@gmail.com> wrote:
>>>> ...
>>>> Similar but not quite; the idea is that you know that there is some
>>>> code (I'm just talking about files here, so lets ignore hunks for the
>>>> moment) which is normally checked in but for a period of time you want
>>>> it ignored. So you don't want it git ignored but at the same time you
>>>> don't want to see these files in the list of modified files.
>>>
>>> What is the reason git ignore is no good in this case? Is it simply
>>> that you can't see the ignored files in git status, or is it that
>>> adding and removing entries to .gitignore is too cumbersome? If it's
>>> the latter you could probably put together a simple shell wrapper to
>>> automate the task, as otherwise it seems like git ignore does what you
>>> need.
>>
>> Git ignore doesn't ignore tracked files.
>
> would 'git update-index --assume-unchanged' work in this case?  Didn't
> see it mentioned in any of the replies so far (but I have never used
> it myself)
>From the help page:
--assume-unchanged, --no-assume-unchanged
    ...
    This option can be also used as a coarse file-level mechanism to
ignore uncommitted changes in tracked files (akin to what .gitignore
    does for untracked files).

Seems like it does everything required. I tested and it correctly hides changes that I want hidden. The only thing I can't see how to do is get git status to show files with the assume unchanged bit set. I think there is no way currently, but that might be a nice addition to make the initial request feature complete. It could show either all files with the bit set, or files with the bit set that have been changed (or this could be configurable).

Regards,
Andrew Ardill
Marco Craveiro· Oct 5, 2012, 06:09 UTC · re: Andrew Ardill · lore

Re: Ignore on commit

<git update-index --assume-unchanged>
Show 16 quoted lines
> From the help page:
>
> --assume-unchanged, --no-assume-unchanged
>     ...
>
>     This option can be also used as a coarse file-level mechanism to
> ignore uncommitted changes in tracked files (akin to what .gitignore
>     does for untracked files).
>
> Seems like it does everything required. I tested and it correctly
> hides changes that I want hidden. The only thing I can't see how to do
> is get git status to show files with the assume unchanged  bit set. I
> think there is no way currently, but that might be a nice addition to
> make the initial request feature complete. It could show either all
> files with the bit set, or files with the bit set that have been
> changed (or this could be configurable).
This is indeed the solution outlined in [4] on my original post:
http://gitready.com/intermediate/2009/02/18/temporarily-ignoring-files.html

The presence in git status is quite important or else one has to change the regular workflow with a second status command.

Cheers
Marco
-- 
So young, and already so unknown -- Pauli

blog: http://mcraveiro.blogspot.com
Philip Oakley· Oct 5, 2012, 07:00 UTC · re: Andrew Ardill · lore

Re: Ignore on commit

From: "Andrew Ardill" <andrew.ardill@gmail.com>
Show 17 quoted lines
> On 5 October 2012 07:20, Marco Craveiro <marco.craveiro@gmail.com> 
> wrote:
>> ...
>> Similar but not quite; the idea is that you know that there is some
>> code (I'm just talking about files here, so lets ignore hunks for the
>> moment) which is normally checked in but for a period of time you 
>> want
>> it ignored. So you don't want it git ignored but at the same time you
>> don't want to see these files in the list of modified files.
>
> What is the reason git ignore is no good in this case? Is it simply
> that you can't see the ignored files in git status, or is it that
> adding and removing entries to .gitignore is too cumbersome? If it's
> the latter you could probably put together a simple shell wrapper to
> automate the task, as otherwise it seems like git ignore does what you
> need.
>

IIUC the files are already tracked, and a variant of ' git update-index --assume-unchanged' is being requested, so that the command doesn't need to be repeated if they checkuout / swap branches (which assumes I've understood the effect of such an index change correctly)

> Regards,
>
> Andrew Ardill
> --
Pascal Obry· Oct 5, 2012, 13:30 UTC · re: Marco Craveiro · lore

Re: Ignore on commit

Marco,
> Similar but not quite; the idea is that you know that there is some
> code (I'm just talking about files here, so lets ignore hunks for the
> moment) which is normally checked in but for a period of time you want
> it ignored. 
Got it thanks! Would be useful some time indeed.
-- 
  Pascal Obry /  Magny Les Hameaux (78)

  The best way to travel is by means of imagination

  http://v2p.fr.eu.org
  http://www.obry.net

  gpg --keyserver keys.gnupg.net --recv-key F949BD3B

← back to recent threads