shell - How to archive modified files between two git branch using command git archive? -


i use such command archive modified files between master , head:

git archive --format=zip -o diff_archive.zip head `git diff --name-only master..head` 

however, if there no modified file, files in working copy archived, there way avoid this?

now,what use dummy file, , change command this:

git archive --format=zip -o diff_archive.zip head dummy_file `git diff --name-only master..head` 

it solves problem, not elegantly, dummy_file archived.

assuming don't mind fact operation not @ safe oddly named files or include whitespace. can following:

files=$(git diff --name-only master..head) git archive --format=zip -o diff_archive.zip head ${files:-no_such_file} 

and git archive error on non-existent file. (this uses use default value version of parameter expansion.)

if rather avoid error use git diff --exit-code:

if ! _files=$(git diff --exit-code --name-only master..head); git archive --format=zip -o diff_archive.zip head $files fi

(this needs ! invert exit code because git diff (like diff itself) exits 1 when there differences , 0 when there aren't any).


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -