-
Notifications
You must be signed in to change notification settings - Fork 5
Comparing and patching changes
This are some commands how to compare the changes between different parts of this SDK/repository and how to patch them.
Show statistic:
git diff official..master --name-only | grep -v '^\.' | grep -v '^doc' | xargs git diff --stat --color official..master --
Create patch file:
git diff official..master --name-only | grep -v '^\.' | grep -v '^doc' | xargs git diff official..master -- > diff.patch
What it does:
-
git diff official..master --name-only
gets all different files of the official branch and the master (community) branch -
grep -v '^\.' | grep -v '^doc'
exclude all hidden files (starting with .) and the doc directories -
xargs git diff --stat --color official..master
displays a statistic of the differences (OR) -
xargs git diff official..master -- > diff.patch
saves the differences into the patch filediff.patch
Provided that you have two directories - threema-msgapi-sdk-php
with a cloned version of this repo and threema-msgapi-sdk-php-x.x.x
with a version downloaded (from the Threema homepage) - you can compare the directories like this:
diff -u -r -x '*.md' threema-msgapi-sdk-php threema-msgapi-sdk-php-x.x.x > diff.patch
Alternatively you may use this command if the one before does not work:
diff -c -r -x '*.md' threema-msgapi-sdk-php threema-msgapi-sdk-php-x.x.x > diff.patch
What it does:
-
diff
compares the two directories afterwards -
-r
also compares all files in subdirectories -
-u
uses the "unified" format which can be used by GNU diff and patch (OR) -
-c
uses the "compact" format, which is more common -
-x '*.md'
excludes all markdown files. If there are changes they should be integrated manually. -
> diff.patch
saves the output to a file, so it creates a patch
In case you get "empty files" which are changed or a very large patch file, this may be due to different line endings. You can fix it like this.
Fast mode:
find threema-msgapi-sdk-php -not -path '*/\.*' -type f -not \( -name '*.jpg' -o -name '*.png' -o -name '*.phar' -o -name '*.woff' -o -name '*.tff' -o -name '*.off' \) -print0 | xargs -0 -n 5 -P 4 dos2unix -k
Slow mode:
find threema-msgapi-sdk-php -not -path '*/\.*' -type f -not \( -name '*.jpg' -o -name '*.png' -o -name '*.phar' -o -name '*.woff' -o -name '*.tff' -o -name '*.off' \) -exec dos2unix -k {} \;
What it does:
-
find threema-msgapi-sdk-php
looks in the directorythreema-msgapi-sdk-php
. You may use.
instead if you are already in the directory of the repo. -
-not -path '*/\.*'
excludes hidden files starting with a dot (.
) like.git
-
-type f
says it should find files -
-not \( -name '*.jpg' -o -name '*.png' [...] \)
excludes files which may break if they are modified: .jpg, .png, .phar, .woff, .tff, .off -
-print0
passes the output to the next command -
xargs -0 -n 5 -P 4
executes the following command in a speed-optimized mode (4 processors used for 5 files each). Alternatively-exec
is used in the second mode to process all files at once. -
dos2unix
converts theCRLF
line endings to Unix ones (LF
) -
-k
makes sure the modification date is not changed (just a cosmetic thing)
Note than git diff
also uses the compact (-u
) format. In most cases it is possible to exchange the commands and still execute them successfully. However by using the correct command you also used when creating the patches you are on the safe side.
git apply gitdiff.patch
Replace diff.patch
with the filename of your patch.
patch -u -p1 -i diff.patch
If you used the -c
option previously you also have to use it now:
patch -c -p1 -i diff.patch
What it does:
-
patch
applies the patch file -
-u
or-c
specifies the format of the patch file (see above) -
-p1
specifies how many directories should be ignored starting from the patch path. If you previously were in one of the patch directories use-p0
to keep all file paths. -
-i diff.patch
is the file which should be used
Thanks to these people/sources. If you get stuck at a specific part you may use them for further information.