user1015149
user1015149

Reputation: 187

Git: Any way to ignore files that have gotten version number changed only

I'm trying to look at some changes done in a new version of a software named IP.Board. However, when I run a git show between their version 3.4.2 and 3.4.3 in my local repo there is a lot of files that have just gotten their version number updated.

Like this:

- * IP.Board v3.4.2
+ * IP.Board v3.4.3

Any simple way I can ignore the files where this is the only change made? I guess their version builder automatically updates the version number in all included files.

Upvotes: 1

Views: 322

Answers (3)

Carl
Carl

Reputation: 44438

No you can't. I know this is not what you want, but I would suggest living with the problem.

Yes, it sucks. However, trying to solve it (or lessen the headache) at the git level is only ensuring that you will live with the problem for longer. The fact is that this is a consequence of a poor design choice when setting up the builds.

You can ignore the files, but you will first have to remove them from git:

  1. Backup the files you're about to remove
  2. git rm <files>
  3. commit
  4. Restore the files.
  5. Edit .gitignore and add the restored files until git says your working tree is clean.

If that's not workable, the best you could do is use a combination of scripts that function as commit hooks that automate as much of the process of managing these files as possible. It will still be a pain, but less so. Again, I recommend you don't go down this path.

UPDATE: If you're not going to be changing those version numbers yourself, you could also use a filter ( a script that takes two commands - smudge and clean). When the command is smudge, your script would remove the lines with the version number, similar to what William has noted. When the command is clean, your script would add the lines back in.

Note, the key difference between this and William's approach is that using this, even if you open the file in a normal text editor, you won't see the version lines, because this approach would actually modify the file's content - not git's view of it. Therefore, this may not be what you want - the safest approach is what William has suggested, which is changing the way git sees differences.

Here is more info on both these approaches.

Upvotes: 0

William Pursell
William Pursell

Reputation: 212198

This is not incredibly robust, but maybe good enough. In .git/config put:

[diff "remove-rev"]
    textconv=sed '/IP.Board v[0-9]*\\.[0-9]*\\.[0-9]*/d'

And then in .gitattributes or .git/info/attributes, put:

* diff=remove-rev

Now, whenever git-diff is run, the sed script will be applied to the file before gitdiffcore decides which file pairs differ. You may need to tweek the sed command to suit your needs, but this should help.

Upvotes: 5

zzk
zzk

Reputation: 1387

No. git tracks the content of the file using hash of the file's content. When the version changes, the content change, and so will the hash.

Upvotes: 0

Related Questions