Skip to contentSkip to conversation

git refuses to switch to older branches

DISCUSSION Martin Waitz 7 participants 15 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

hoi :)

now that gitweb.cgi is autogenerated, git refuses to switch to old branches unless force is applied:

fatal: Untracked working tree file 'gitweb/gitweb.cgi' would be overwritten by merge.

This safety measure is quite useful normally, but for files that are explicitly marked as to-be-ignored it should not be neccessary.

But all the code that handles .gitignore is only used by ls-files now. Does it make sense to add exclude handling to unpack-trees.c, too?

Signature · 1 line
Martin Waitz
#1 lore raw
Quoted 5 lines · Martin Waitz

This safety measure is quite useful normally, but for files that are explicitly marked as to-be-ignored it should not be neccessary.

But all the code that handles .gitignore is only used by ls-files now. Does it make sense to add exclude handling to unpack-trees.c, too?

In principle, I am not opposed to the idea of making read-tree take the ignore information into consideration.

But I would suggest you to be _extremely_ careful if you want to try this. I do not have an example offhand, but I would not be surprised at all if there is a valid use case where it is useful to have a pattern that matches a tracked file in .gitignore file.

#2 lore raw

Dear diary, on Sun, Aug 20, 2006 at 12:39:20AM CEST, I got a letter where Junio C Hamano <[email protected]> said that...

Quoted 5 lines

But I would suggest you to be _extremely_ careful if you want to try this. I do not have an example offhand, but I would not be surprised at all if there is a valid use case where it is useful to have a pattern that matches a tracked file in .gitignore file.

*.o and binary blobs of closed-source software.

Signature · 4 lines
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
Snow falling on Perl. White noise covering line noise.
Hides all the bugs too. -- J. Putnam
#3 lore raw

hoi :)

Quoted 9 lines · Petr Baudis

Dear diary, on Sun, Aug 20, 2006 at 12:39:20AM CEST, I got a letter where Junio C Hamano <[email protected]> said that...

Quoted 5 lines

But I would suggest you to be _extremely_ careful if you want to try this. I do not have an example offhand, but I would not be surprised at all if there is a valid use case where it is useful to have a pattern that matches a tracked file in .gitignore file.

*.o and binary blobs of closed-source software.

but if you want to switch from one branch which has the .o file built from source to another branch which has the .o file tracked in binary form, wouldn't you want to remove the generated file in order to store the tracked one from the new branch?

Signature · 1 line
Martin Waitz
#4 lore raw

Hi,

Quoted 9 lines · Martin Waitz
Quoted 8 lines · Petr Baudis

Dear diary, on Sun, Aug 20, 2006 at 12:39:20AM CEST, I got a letter where Junio C Hamano <[email protected]> said that...

Quoted 5 lines

But I would suggest you to be _extremely_ careful if you want to try this. I do not have an example offhand, but I would not be surprised at all if there is a valid use case where it is useful to have a pattern that matches a tracked file in .gitignore file.

Quoted 6 lines
Quoted 1 line

*.o and binary blobs of closed-source software.

but if you want to switch from one branch which has the .o file built from source to another branch which has the .o file tracked in binary form, wouldn't you want to remove the generated file in order to store the tracked one from the new branch?

Not necessarily. Sometimes you have files in your working directory, which are not in your repository, you know?

Ciao,
Dscho

#5 lore raw

hoi :)

Quoted 12 lines · Johannes Schindelin
Quoted 11 lines · Martin Waitz
Quoted 9 lines · Petr Baudis

Dear diary, on Sun, Aug 20, 2006 at 12:39:20AM CEST, I got a letter where Junio C Hamano <[email protected]> said that...

Quoted 5 lines

But I would suggest you to be _extremely_ careful if you want to try this. I do not have an example offhand, but I would not be surprised at all if there is a valid use case where it is useful to have a pattern that matches a tracked file in .gitignore file.

*.o and binary blobs of closed-source software.

Quoted 7 lines
Quoted 4 lines

but if you want to switch from one branch which has the .o file built from source to another branch which has the .o file tracked in binary form, wouldn't you want to remove the generated file in order to store the tracked one from the new branch?

Not necessarily. Sometimes you have files in your working directory, which are not in your repository, you know?

Sure. But we are only talking about files which are explicitly ignored in one branch and are tracked in another branch.

Perhaps it makes sense to check that the file is _not_ ignored in the other branch (in which it is tracked).
Would such a check make everybody happy?

Is there an easy way to check if some file is marked as ignored in an other branch?

Signature · 1 line
Martin Waitz
#6 lore raw

Hi,

Quoted 23 lines · Martin Waitz

hoi :)

Quoted 12 lines · Johannes Schindelin
Quoted 11 lines · Martin Waitz
Quoted 9 lines · Petr Baudis

Dear diary, on Sun, Aug 20, 2006 at 12:39:20AM CEST, I got a letter where Junio C Hamano <[email protected]> said that...

Quoted 5 lines

But I would suggest you to be _extremely_ careful if you want to try this. I do not have an example offhand, but I would not be surprised at all if there is a valid use case where it is useful to have a pattern that matches a tracked file in .gitignore file.

*.o and binary blobs of closed-source software.

Quoted 7 lines
Quoted 4 lines

but if you want to switch from one branch which has the .o file built from source to another branch which has the .o file tracked in binary form, wouldn't you want to remove the generated file in order to store the tracked one from the new branch?

Not necessarily. Sometimes you have files in your working directory, which are not in your repository, you know?

Quoted 6 lines

Sure. But we are only talking about files which are explicitly ignored in one branch and are tracked in another branch.

Perhaps it makes sense to check that the file is _not_ ignored in the other branch (in which it is tracked).
Would such a check make everybody happy?

Actually, I am very happy with the strict checking, and that I can override it with "-f".

Ciao,
Dscho

#7 lore raw
In reply to Johannes Schindelin
Quoted 2 lines · you

Not necessarily. Sometimes you have files in your working directory, which are not in your repository, you know?

Yet, I think it is quite inconvenient the way it is now. The same happens if you track a generated file by accident, and remove it later from tracking.

The real problem is that there are two reasons to put a file into .gitignore:
You do not want to have it tracked and polluting git-status because
(1) it is temporary and generated
(2) it is private and not supposed to be in the repository

To distinguish these cases, we could introduce a per-repository configuration file .git/nevertouch . Comments?

Josef

#8 lore raw
In reply to Junio C Hamano

Junio C Hamano, Sun, Aug 20, 2006 00:39:20 +0200:

Quoted 5 lines
Quoted 3 lines · Martin Waitz

This safety measure is quite useful normally, but for files that are explicitly marked as to-be-ignored it should not be neccessary.

Quoted 7 lines
Quoted 2 lines

But all the code that handles .gitignore is only used by ls-files now. Does it make sense to add exclude handling to unpack-trees.c, too?

In principle, I am not opposed to the idea of making read-tree take the ignore information into consideration.

But I would suggest you to be _extremely_ careful if you want to

It should be optional. And off by default, people already have got scripts depending on this behaviour (well, I have).

Quoted 5 lines

try this. I do not have an example offhand, but I would not be surprised at all if there is a valid use case where it is useful to have a pattern that matches a tracked file in .gitignore file.

Ignored directory and but some files/subdirectories in it are tracked, because this is temporary or externally changed data (I have both examples).

#9 lore raw

hoi :)

Quoted 9 lines · Alex Riesen

Junio C Hamano, Sun, Aug 20, 2006 00:39:20 +0200:

Quoted 8 lines
Quoted 5 lines · Martin Waitz

This safety measure is quite useful normally, but for files that are explicitly marked as to-be-ignored it should not be neccessary.

But all the code that handles .gitignore is only used by ls-files now. Does it make sense to add exclude handling to unpack-trees.c, too?

Quoted 7 lines
Quoted 4 lines

In principle, I am not opposed to the idea of making read-tree take the ignore information into consideration.

But I would suggest you to be _extremely_ careful if you want to

It should be optional. And off by default, people already have got scripts depending on this behaviour (well, I have).

but having this sort of behaviour optional is bad, I think. Some people will depend on one semantic and others on the other. And then get bite if they want to share their scripts. We have to find _one_ semantic that always works.

Quoted 8 lines
Quoted 4 lines

try this. I do not have an example offhand, but I would not be surprised at all if there is a valid use case where it is useful to have a pattern that matches a tracked file in .gitignore file.

Ignored directory and but some files/subdirectories in it are tracked, because this is temporary or externally changed data (I have both examples).

but do you have non-tracked files in the ignored directory that you really care about, i.e. which must not be overridden by a tracked file with the same name?

Signature · 1 line
Martin Waitz
#11 lore raw
In reply to Martin Waitz
Quoted 11 lines · Martin Waitz

now that gitweb.cgi is autogenerated, git refuses to switch to old branches unless force is applied:

fatal: Untracked working tree file 'gitweb/gitweb.cgi' would be overwritten by merge.

This safety measure is quite useful normally, but for files that are explicitly marked as to-be-ignored it should not be neccessary.

But all the code that handles .gitignore is only used by ls-files now. Does it make sense to add exclude handling to unpack-trees.c, too?

I think it is "better to be annoying but safe" idea of git. You can always do "git checkout <branch> gitweb/gitweb.cgi" and "git checkout <branch>", and not use -f.

Or add gitweb.cgi to .gitignore in the old branch.

Signature · 3 lines
Jakub Narebski
Warsaw, Poland
ShadeHawk on #git
#12 lore raw
Quoted 11 lines · Jakub Narebski
Quoted 9 lines · Martin Waitz

now that gitweb.cgi is autogenerated, git refuses to switch to old branches unless force is applied:

fatal: Untracked working tree file 'gitweb/gitweb.cgi' would be overwritten by merge.

This safety measure is quite useful normally, but for files that are explicitly marked as to-be-ignored it should not be neccessary.

Quoted 6 lines
Quoted 2 lines

But all the code that handles .gitignore is only used by ls-files now. Does it make sense to add exclude handling to unpack-trees.c, too?

I think it is "better to be annoying but safe" idea of git. You can always do "git checkout <branch> gitweb/gitweb.cgi" and "git checkout <branch>", and not use -f.

I think you are talking backwards. Newer branch have .cgi generated and older branch has it tracked. After you have built in a newer branch, checking out an older branch without -f option would play it safe not to clobber .cgi which is annoying. So workaround you would want to suggest is TO USE -f.

Quoted 1 line

Or add gitweb.cgi to .gitignore in the old branch.

And this "adding something to old one" is nonsense ;-).

#13 lore raw
Quoted 20 lines · Junio C Hamano
Quoted 11 lines · Jakub Narebski
Quoted 9 lines · Martin Waitz

now that gitweb.cgi is autogenerated, git refuses to switch to old branches unless force is applied:

fatal: Untracked working tree file 'gitweb/gitweb.cgi' would be overwritten by merge.

This safety measure is quite useful normally, but for files that are explicitly marked as to-be-ignored it should not be neccessary.

Quoted 6 lines
Quoted 2 lines

But all the code that handles .gitignore is only used by ls-files now. Does it make sense to add exclude handling to unpack-trees.c, too?

I think it is "better to be annoying but safe" idea of git. You can always do "git checkout <branch> gitweb/gitweb.cgi" and "git checkout <branch>", and not use -f.

Quoted 5 lines

I think you are talking backwards. Newer branch have .cgi generated and older branch has it tracked. After you have built in a newer branch, checking out an older branch without -f option would play it safe not to clobber .cgi which is annoying. So workaround you would want to suggest is TO USE -f.

If I remember correctly that is what I did when "master" (and I had switch to master to do "git pull origin") didn't contain gitweb.cgi -> gitweb.perl rename. My proposed solution first overwrites generated gitweb.cgi by tracked file (i'm not sure if this is feature or bug that git-checkout with file specified (path limit specified?) doesn't need -f, and then you can do git-checkout full branch without -f.

Signature · 3 lines
Jakub Narebski
Warsaw, Poland
ShadeHawk on #git
#14 lore raw
Quoted 2 lines · Jakub Narebski

... I'm not sure if this is feature or bug that git-checkout with file specified (path limit specified?) doesn't need -f

This is definitely a feature we deliberately added long after git-checkout was initially written, in reponse to specific requests from users. Back then the only way to revert to index or HEAD was to "checkout-index -f -q -u -a" or "reset --hard" and it was cumbersome to revert only a single path.

I have been wondering if we wanted to be able to say:

git checkout HEAD gitweb/

to revert everything under named hierarchy, but we haven't heard user requests for this. This is way more dangerous than my liking so personally I am happy that we do not have it.

#10 lore raw
In reply to Martin Waitz

Sorry for the answer long overdue, I was on vacation, and quite off of the internet.

Martin Waitz, Sun, Aug 20, 2006 14:19:35 +0200:

Quoted 13 lines · Alex Riesen
Quoted 12 lines

Junio C Hamano, Sun, Aug 20, 2006 00:39:20 +0200:

Quoted 11 lines
Quoted 5 lines · Martin Waitz

This safety measure is quite useful normally, but for files that are explicitly marked as to-be-ignored it should not be neccessary.

But all the code that handles .gitignore is only used by ls-files now. Does it make sense to add exclude handling to unpack-trees.c, too?

In principle, I am not opposed to the idea of making read-tree take the ignore information into consideration.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

But I would suggest you to be _extremely_ careful if you want to

It should be optional. And off by default, people already have got scripts depending on this behaviour (well, I have).

but having this sort of behaviour optional is bad, I think. Some people will depend on one semantic and others on the other. And then get bite if they want to share their scripts.

So at least give the people who got there first a chance to have their scripts working. Why break them?

Quoted 1 line

We have to find _one_ semantic that always works.

Well, the current semantics always work.

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

try this. I do not have an example offhand, but I would not be surprised at all if there is a valid use case where it is useful to have a pattern that matches a tracked file in .gitignore file.

Quoted 8 lines
Quoted 3 lines

Ignored directory and but some files/subdirectories in it are tracked, because this is temporary or externally changed data (I have both examples).

but do you have non-tracked files in the ignored directory that you really care about, i.e. which must not be overridden by a tracked file with the same name?

I don't, but I can easily imagine someone has: a file contained some build-local configuration, which developer later decided to start tracking. Like config.mak in git.