r0tt
r0tt

Reputation: 379

GIT archive only if files have been changed in git

We are using git archive to deploy scripts on a jump server which than uses rsync to deploy this files on target machines. The git archive cronjob runs every 24h and the files, which are archive from git get a new creation date on the jump server every time. Rsync now synchronizes all this files, which actually have not changed. Is there any way to tell git archive to not replace the files on the jump server if the file has not been changed in git?

Upvotes: 0

Views: 130

Answers (1)

LeGEC
LeGEC

Reputation: 51932

You can pass a list of files to git archive :

git archive -o ../myarchive.tgz -- path/to/file1 path/to/file2

You can combine this with git diff --name-only :

# - diff-filter=AM: list only Added or Modified files (not Deleted ones)
# - --no-renames: turn off rename detection, you don't want to overlook files that are flagged
#   as renamed or copied
git archive ...  -- $(git diff --no-renames --diff-filter=AM --name-only [previouscommit] HEAD)

Note that this will only include created and modified files, if you need to also delete files, you will need an extra delete step :

# delete files listed in :
git diff --no-renames --diff-filter=D --name-only [previouscommit] HEAD

Upvotes: 1

Related Questions