开发者

Git Diff - Indicate a line move

I'm developing a script to use with git diff to be able to 'filter out' lines that have simply moved in a file. Visual Studio 2008 has become a pain when working with Designer files. It sometimes seems to insist on rewriting the entire file in a different order. This makes it dif开发者_如何学运维ficult to see the real changes to the file. I'm piping git diff into a script to tweak the output of git diff. I could either remove the lines from the output or I could replace the +/- with different symbols to indicate a move but I'm not sure which symbols to use.


This is not an answer to the question but a possible alternative solution to the problem described.

I'm not familiar with Visual Studio 2008 or Designer files but I have run into a solution where I wanted to store files in git that were being generated by another program. The order of lines in some of the files didn't matter at all. In other files, the order was not important but a simple sort was inadequate because it contained nested data structures.

My solution was to make use of filters in git to alter the file contents before they were committed. This is configured in two parts. First you need to assign a filter to the files using a .gitattributes file.

*.list      filter=sort

Next the behavior of the filter needs to be defined in the config file. This can either be done in your user config ~/.gitconfig, or in the repos config .git/config. This is local only and not shared with others automatically as part of the repo so if you want others to do this too then you need to tell them.

[filter "sort"]
    clean = sort
    smudge = cat

The result of this simple filter was that when the files were committed to the repo, instead of the lines being in the random order from the program that created them, they were sorted alphanumerically and only additions, removals, and changes appeared in the diffs.

Now I mentioned that I had two different file types two work with, a simple one and a complex one. For the complex one which contained nested datatypes (Lua tables to be specific), I created (with a lot of help from somebody else) a script to read the file contents, sort each nested section, and output the sorted result without altering the behavior when the data was later used.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜