2

In my project there is a directory (i.e. db/updates/) where all updates of DB are stored. Each update is in single file (i.e. update_1.sql, update_2.sql etc). When release is made I need scope of files that where added/updated since last revision (which stored in DB). Now I'm doing it the following way:

# pull changes    
git pull origin branch --force

# make patch    
git diff $last_revision -- ./db/updates > ./PATCH

# remove all files in directory /db/updates    
rm -rf ./db/updates/*

# apply changes    
git apply --ignore-whitespace --inaccurate-eof ./PATCH

It works fine, but there are cases when it fails. If there were changes in files between commits B and C in files that where added with commit A the patch will fail with error error: db/updates/update_xxx.sql : No such file or directory

How to ignore missing files? I'd use --diff-filter=A while creating patch, but this will ignore all changes that where commited between needed revision B and C.

user3044784
  • 81
  • 1
  • 4

2 Answers2

1

Try filtering for only added files:

git diff --diff-filter=A $last_revision -- ./db/updates > ./PATCH

That would give you only newly added files in your patch, instead of modified ones.

See more at "Filter git diff by type of change":
To get new and modified files:

git diff --diff-filter=ACMR $last_revision -- ./db/updates > ./PATCH
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
1

Well, there is even easier way to get added/modified files without any problems with patches and so on:

# pull changes
git pull origin branch --force

# get modified files list since last revision
modified=`git diff --name-only last_revision -- ./db/updates`

# copy added/modified to another folder
for sql in $modified; do
    cp $sql ./temp/
done
user3044784
  • 81
  • 1
  • 4