0

When using vhdl-mode in emacs, there is a template that creates a header with some useful information. One of the lines contains the date of the last update and is automatically updated by emacs when the file is saved:

-- Last update: 2016-04-27

The problem with this is that every time I do a git pull or similar that performs a merge, I will get a conflict on this line since the date will be different.

Is there a way to get git to ignore lines that starts with e.g. "-- Last update:" and just use the latest version.
I.e. It should not ignore the line at commit as being asked for in other questions, it should ignore the contents at merge or avoid a conflict

Bimme
  • 127
  • 2
  • 12
  • 1
    Possible duplicate of [Can git ignore a specific line?](http://stackoverflow.com/questions/6557467/can-git-ignore-a-specific-line) – xero Apr 27 '16 at 19:49
  • What does this have to do with emacs or vhdl? – PlayDough Apr 27 '16 at 19:52
  • @PlayDough: It is vhdl mode in emacs that gives me the problem. I imagine that some other vhdl developers using emacs have got the same problem. – Bimme Apr 28 '16 at 12:08
  • That automatic updating of the timestamp when you save the file is a built in emacs feature (see the manual for details). You can probably turn it off. . I use it all the time with many different languages (but not vhdl) and rarely get merge conflicts over the timestamp. Have you modified your git config to tweak the merge strategy? GIT should be able to handle this type of conflict in most cases with the correct workflow. Make sure your making changes in a topic branch which you merge back into master after doing a pull and git should be able to resolve the conflicts more often – Tim X Apr 29 '16 at 22:25

1 Answers1

3

Merge works on branches using the commits that compose them. Commits operate on lines of files. By the time you reach merge time, you have already committed changes to those lines and pushed those changes to a branch.

So the way to get git to ignore those lines at merge time is to never have committed them in the first place. Using git partial add, you can interactively select what lines to include in a commit or leave in the working directory uncommitted:

git add -p [file_or_dir]

But once you compose the commits with those lines included, to do its job, merge must attempt to apply them. See also, interactive rebase (with edit), for retouching previous commits:

git rebase -i HEAD~[N]

Where N is the number of commits backwards you intend to rewrite. The usual warnings about rebase changing history apply here, so only do this with your topic branches (not published branches where others rely on your history).

Joe Atzberger
  • 3,079
  • 1
  • 18
  • 16
  • Thanks for your suggestion, but since it is a standard header from vhdl mode I have a lot of files that already have the header. The easy solution would be to remove the line, but I imagine that other vhdl developers using vhdl mode in emacs have the same problem. – Bimme Apr 28 '16 at 12:18
  • Right, I would suggest removal and a project .emacs file that specifies configuration for the editor not to reinsert the line. – Joe Atzberger Apr 30 '16 at 01:08