-
-
Save YaroslavShapoval/cbab1fe98adb14ddc2cf to your computer and use it in GitHub Desktop.
| #!/bin/sh | |
| # default owner user | |
| OWNER="www-data:www-data" | |
| # changed file permission | |
| PERMISSION="664" | |
| # web repository directory | |
| REPO_DIR="/var/www/sitename" | |
| # remote repository | |
| REMOTE_REPO="origin" | |
| # public branch of the remote repository | |
| REMOTE_REPO_BRANCH="master" | |
| cd $REPO_DIR || exit | |
| unset GIT_DIR | |
| files="$(git diff-tree -r --name-only --no-commit-id HEAD@{1} HEAD)" | |
| git merge FETCH_HEAD | |
| for file in $files | |
| do | |
| sudo chown $OWNER $file | |
| sudo chmod $PERMISSION $file | |
| done | |
| exec git-update-server-info |
git diff-tree -r --name-only --no-commit-id HEAD@{1} HEADThe format of the command above is
git diff-tree <commit_ID_start> <commit_ID_end>First of all, let's take a look at diff-tree, what does it use for? Actually diff-tree shows the differences from <commit_ID_start> to <commit_ID_end> from reflog, in this case, HEAD@{1} is the <commit_ID_start> and HEAD is the <commit_ID_end>.
Now we can change the command as below
git diff-tree HEAD@{1} HEADNow, run git reflog, you should know what HEAD@{1} means, actually it stands for the last reflog, while HEAD@{0} stands for the current reflog(which is HEAD)

So, git diff-tree HEAD@{1} HEAD is use to show the difference from the last commit HEAD@{1} and the current HEAD@{0}(HEAD) from the reflog.
As to --name-only and --no-commit-id, they are the options of diff-tree, see the command and it's output below
> git diff-tree HEAD@{1} HEAD
:000000 100644 0000000000000000000000000000000000000000 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 A README.md
:000000 100644 0000000000000000000000000000000000000000 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 A aaa.html
:100644 000000 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0000000000000000000000000000000000000000 D test.txt
> git diff-tree --name-only HEAD@{1} HEAD
README.md
aaa.html
test.txt
well, if --name-only can get the name, what does --no-commit-id use for? see the screenshot below(screenshot from git diff-tree --help)

As to -r, I think you already know, it refers to recursively.
can you run me through what this is doing?
files="$(git diff-tree -r --name-only --no-commit-id HEAD@{1} HEAD)"specifically the
--no-commit-id HEAD@{1} HEAD