threads / discuss / 44133

.gitignore does not ignore Makefile

Subject: .gitignore does not ignore Makefile

## tl;dr

6 messages between Sep 22, 2016 and Sep 23, 2016.

replies: 5people: 4as markdown or json

Timur Tabi· Sep 22, 2016, 14:19 UTC · lore
I have the following .gitignore file in patch arm/arm64/boot/dts:

*.dtb qcom qcom.orig

When I do a git status, I see this:
    modified:   .gitignore
    modified:   qcom/Makefile

All of the other files in arm/arm64/boot/dts/qcom are being ignored, as request. However, the file "Makefile" is not being ignored. Why? What's so special about "Makefile" that git refuses to ignore it?

-- 
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project.
Kevin Daudt· Sep 22, 2016, 15:44 UTC · re: Timur Tabi · lore

Re: .gitignore does not ignore Makefile

On Thu, Sep 22, 2016 at 09:19:22AM -0500, Timur Tabi wrote:
Show 15 quoted lines
> I have the following .gitignore file in patch arm/arm64/boot/dts:
> 
> *.dtb
> qcom
> qcom.orig
> 
> When I do a git status, I see this:
> 
>     modified:   .gitignore
>     modified:   qcom/Makefile
> 
> All of the other files in arm/arm64/boot/dts/qcom are being ignored,
> as request.  However, the file "Makefile" is not being ignored.  Why?
> What's so special about "Makefile" that git refuses to ignore it?
> 

There is nothing special about the Makefile, except that it's tracked. Git never ignores tracked files (almost a paradox).

You can untrack the file by doing git rm --cached <file>, which new commits won't have this file.

If your goal is to ignore local changes to a tracked file, then the advise is to reconsider your plan.

Often people advise tricks like `git update-index --assume-unchanges <file>`, but this does not work as expected. It's merely a promise to git that this file does not change (and hence, git will not check if this file has changed when doing git status), but command that try to change this file will abort saying that the file has changed.

Hope this helps,
Kevin.
Junio C Hamano· Sep 22, 2016, 18:26 UTC · re: Kevin Daudt · lore

Re: .gitignore does not ignore Makefile

Kevin Daudt <me@ikke.info> writes:
Show 5 quoted lines
> Often people advise tricks like `git update-index --assume-unchanges
> <file>`, but this does not work as expected. It's merely a promise to
> git that this file does not change (and hence, git will not check if
> this file has changed when doing git status), but command that try to
> change this file will abort saying that the file has changed.

It actually is even worse. As the user promised Git that the <file> will not be modified and will be kept the same as the version in the index, Git reserves the right to _overwrite_ it with the version in the index anytime when it is convenient to do so, removing whatever local change the user had despite the promise to Git. The "abort saying that the file has changed" is merely various codepaths in the current implementation trying to be extra nice.

Timur Tabi· Sep 22, 2016, 18:44 UTC · re: Junio C Hamano · lore

Re: .gitignore does not ignore Makefile

Junio C Hamano wrote:
Show 7 quoted lines
> It actually is even worse.  As the user promised Git that the <file>
> will not be modified and will be kept the same as the version in the
> index, Git reserves the right to_overwrite_  it with the version in
> the index anytime when it is convenient to do so, removing whatever
> local change the user had despite the promise to Git.  The "abort
> saying that the file has changed" is merely various codepaths in the
> current implementation trying to be extra nice.

So .gitignore only ignores new files, not modified ones? That seems odd, but I guess that's the way it's always been and I just haven't noticed until now.

-- 
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm
Technologies, Inc.  Qualcomm Technologies, Inc. is a member of the
Code Aurora Forum, a Linux Foundation Collaborative Project.
Junio C Hamano· Sep 22, 2016, 19:16 UTC · re: Timur Tabi · lore

Re: .gitignore does not ignore Makefile

Timur Tabi <timur@codeaurora.org> writes:
> So .gitignore only ignores new files, not modified ones?

It is determines if an untracked file should be considered by "git add" to add it or ignore it.

Jakub Narębski· Sep 23, 2016, 22:29 UTC · re: Junio C Hamano · lore

Re: .gitignore does not ignore Makefile

W dniu 22.09.2016 o 20:26, Junio C Hamano napisał:
Show 15 quoted lines
> Kevin Daudt <me@ikke.info> writes:
> 
>> Often people advise tricks like `git update-index --assume-unchanges
>> <file>`, but this does not work as expected. It's merely a promise to
>> git that this file does not change (and hence, git will not check if
>> this file has changed when doing git status), but command that try to
>> change this file will abort saying that the file has changed.
> 
> It actually is even worse.  As the user promised Git that the <file>
> will not be modified and will be kept the same as the version in the
> index, Git reserves the right to _overwrite_ it with the version in
> the index anytime when it is convenient to do so, removing whatever
> local change the user had despite the promise to Git.  The "abort
> saying that the file has changed" is merely various codepaths in the
> current implementation trying to be extra nice.
 
There is a trick that works almost as 'ignore changes' for tracked
files, namely `git update-index --skip-worktree <file>`.  From the
documentation:
  Skip-worktree bit
  ~~~~~~~~~~~~~~~~~
  Skip-worktree bit can be defined in one (long) sentence: When
  reading an entry, if it is marked as skip-worktree, then Git
  pretends its working directory version is up to date and read
  the index version instead.
  [...] Writing is not affected by this bit, content safety is still
  first priority. [...]

It works quite well; the only problem is that `git stash` would not stash away your changes, and you would need to unmark such file before saving a stash.

With --assume-unchanged used for ignoring changes to tracked files, you can quite easily lose your work because you are lying to Git.

Note also that in Git classic "ignored" implies unimportant.
-- 
Jakub Narębski

← back to recent threads