diff

Git diff -w ignore whitespace only at start & end of lines

筅森魡賤 提交于 2019-12-03 01:30:22
问题 I love to use git diff -w to ignore whitespace differences. But, I just noticed that it ignores even whitespace differences in the middle of lines. How could I only ignore whitespace differences that come at the start (^) or end ($) of lines? 回答1: For end of line use: git diff --ignore-space-at-eol Instead of what are you using currently: git diff -w (--ignore-all-space) For start of line... you are out of luck if you want a built in solution. However, if you don't mind getting your hands

How to edit a diff/patch file cleanly ? Are there any patch file editors?

心已入冬 提交于 2019-12-03 01:12:10
Scenario: I have a patch file that applies cleanly to my working files, but I do not want all the changes from the patch. Usually, I do vim example.patch , remove unwanted changes and them apply patch -p0 -i example.patch but at times the patch does not apply cleanly, and I have to start over again. Is there a patch file editor that allows users to edit and delete part of the patch and still can apply cleanly ? If you open a diff file in emacs and put the editor in "diff" mode you can actually edit patches and it will update the hunk markers in a smart way. Works really well for me! If you are

Merge changes using vimdiff

白昼怎懂夜的黑 提交于 2019-12-03 00:53:24
问题 In my case, I have two files file1 and file2. Using vimdiff, I want to merge the changes as follows: In first difference, place line from file1 above line from file2. It means difference such as Listing 2 in file2 and List 2 should be List 2 followed by Listing 2 in the merged file. Reverse case in another change. Snapshot is shown below. How can we achieve this using vimdiff? 回答1: You can switch back and forth between the two windows with Ctrl w w . You can copy from one window do a Ctrl w w

How to realize a diff function?

99封情书 提交于 2019-12-03 00:51:59
How can I implement a diff function, such as Stack Overflow's question revision history? You have here a javascript example of the implementation of a diff algorithm. Based on: P. Heckel, A technique for isolating differences between files Comm. ACM, 21, (4), 264--268 (1978). The implementation, itself, has two functions, one of which is recommended for use: diffString( String oldFile, String newFile ) This method takes two strings and calculates the differences in each. The final result is the 'newFile' marked up with HTML (to signify both deletions from the oldFile and additions to the

“Diffing” objects from a relational database

不羁的心 提交于 2019-12-03 00:11:10
Our win32 application assembles objects from the data in a number of tables in a MySQL relational database. Of such an object, multiple revisions are stored in the database. When storing multiple revisions of something, sooner or later you'll ask yourself the question if you can visualize the differences between two revisions :) So my question is: what would be a good way to "diff" two such database objects? Would you do the comparison at the database level? (Doesn't sound like a good idea: too low-level, and too sensitive to the schema). Would you compare the objects? Would you write a

Git diff: is it possible to show ONLY changed lines

微笑、不失礼 提交于 2019-12-03 00:10:33
I'm trying to get only new version of lines which have changed and not all the other info which git diff shows. For: git diff HEAD --no-ext-diff --unified=0 --exit-code -a --no-prefix It shows: diff --git file1 file2 index d9db605..a884b50 100644 --- file1 +++ file2 @@ -16 +16 @@ bla bla bla -old text +new text what I want to see is only: new text Is it possible? Only added lines does not make sense in all cases. If you replaced some block of text and you happend to include a single line which was there before, git has to match and guess. - Usually the output of git diff could be used as input

How to compare files with same names in two different directories using a shell script

荒凉一梦 提交于 2019-12-03 00:10:30
Before moving on to use SVN, I used to manage my project by simply keeping a /develop/ directory and editing and testing files there, then moving them to the /main/ directory. When I decided to move to SVN, I needed to be sure that the directories were indeed in sync. So, what is a good way to write a shell script [ bash ] to recursively compare files with the same name in two different directories? Note: The directory names used above are for sample only. I do not recommend storing your code in the top level :). The diff command has a -r option to recursively compare directories: diff -r

diff to output only the file names

坚强是说给别人听的谎言 提交于 2019-12-03 00:08:31
问题 I'm looking to run a Linux command that will recursively compare two directories and output only the file names of what is different. This includes anything that is present in one directory and not the other or vice versa, and text differences. 回答1: From the diff man page: -q Report only whether the files differ, not the details of the differences. -r When comparing directories, recursively compare any subdirectories found. Example command: diff -qr dir1 dir2 Example output (depends on locale

Percentage value with GNU Diff

拈花ヽ惹草 提交于 2019-12-02 23:59:25
What is a good method for using diff to show a percentage difference between two files? Such as if a file has 100 lines and a copy has 15 lines that have been changed the diff-percent would be 15%. Something like this perhaps? Two files, A1 and A2. $ sdiff -B -b -s A1 A2 | wc would give you how many lines differed. wc gives total, just divide. The -b and -B are to ignore blanks and blank lines, and -s says to suppress the common lines. maibaita https://superuser.com/questions/347560/is-there-a-tool-to-measure-file-difference-percentage has a neat solution for this, wdiff -s file1.txt file2.txt

Telling git to follow moved content (not simply moved files)

白昼怎懂夜的黑 提交于 2019-12-02 23:30:15
While refactoring source code, sometimes you need to move big blocks of text inside a file, or even to a new file. You create a branch refactored and commit away: $git checkout master $git branch refactored $git checkout refactored <move code around> $git commit -m "refactored code" However, people may commit on top of the old pre-refactor branch, changing the code that was moved: $git checkout master <change code that was moved elsewhere on branch refactored> $git commit -m "bugfix" On branch refactored , you then want to incorporate changes made in master : $git checkout refactored $git