Reputation: 2480
I am working on a PAAS app. We provide GIT deployment feature where we pull the code from a Git repo in a temp directory and copy the data to working public directory of the server.
The problem with this approach is that it doesn't remove the files from working public directly which were removed in Git Repo. I see apps like DeployHQ somehow extract that list from Git Commits.
Do I have to parse the Git history for that or are there any opensource tools that extract the list of Deleted/modified files from Git commit history.
Upvotes: 2
Views: 158
Reputation: 54457
This is not necessarily a Git problem, but more a problem of how you copy the files over. If you use the simple cp
command, it will not remove any files that have been deleted in the source folder, it will simply copy over any new or updated files. Your target directory will still contain files that were deleted in the source folder.
Here are two ways of getting this to work:
You basically copy the files from the Git repo to a new, empty directory. Then you remove the previous target folder and rename the new folder to the public folder:
cp -r git_repo/* temp
rm -rf public
mv temp public
This will allow you to do a clean break, since you switch directories using the mv
command. At this point, the new folder will become active. You might run into issues if a process keeps file references open in the old folder.
Instead of using the cp
command, you can use something like rsync
, which will allow you to copy changes, and also remove files that are no longer there. Check out the rsync
man page for more info and examples: http://linux.die.net/man/1/rsync
Here's an example to get you started:
rsync -avrKL --progress -d --delete-excluded --exclude=.git git_repo/ public/
One advantage of rsync
is that it is pretty efficient - it will not copy any unchanged files. Once you have done the first run, it will only copy changes, new files or delete removed files, everything else will be left alone.
One additional benefit of rsync
is that you can customize what it copies, using the --exlude
switches. In a similar manner, you can use --include
switches with wildcard patterns.
To make sure that files deleted in the source folder are removed from the target folder, make sure to use a slash at the end of the source folder in the rsync
command line. This will tell rsync
to synchronize the whole folder.
Upvotes: 2
Reputation: 480
You might like to try the following pattern:
# Fetch the new content, but don't start using it yet
git fetch
# List the deletions between the current content and the incoming
git diff HEAD FETCH_HEAD --summary --diff-filter=D
# Update workspace to the new content
git merge FETCH_HEAD
Upvotes: 0
Reputation: 197
git log --diff-filter=D --summary
This will do. But if you deleted a file and create one with same name it wont list.
Upvotes: 3