Using Git to Archive Modified Files

I am looking for a simple solution to create an archive of a recently modified file.

I get this simple command from google

git archive -o update.zip HEAD $(git diff --name-only HEAD^) 

When I run it in GIT BUSH, it keeps saying fatal: not a valid object name

+7
source share
3 answers

I use this answer in this case which tells me

 tar czf changed-files.tar.gz `git diff --name-only [diff options]` 

For example, to create an archive containing files modified in the last four versions, I would do

 tar czf changed-files.tar.gz `git diff --name-only HEAD~4..` 

This assumes - of course - that HEAD~4 does exist.

+12
source

I use this alias to include new files not in HEAD:

 alias gittar='tar -czvf working-files.tgz \ $(git status -s | sed -r "s/..(.*)/\1 /")' 
+1
source

You just need to filter out the files deleted during this comparison to fix this error:

 git archive -o update.zip HEAD $(git diff --name-only --diff-filter=d HEAD^..HEAD) 

Maybe git archive is an extra task for this task, and you should use @eckes answer .
But you should still add --diff-filter=d to exclude deleted files from the archive.

0
source

Source: https://habr.com/ru/post/912460/


All Articles