git 如何提取已提交的文件_从Git提交中获取已删除的文件列表

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.

解决方案

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:

Option 1: Rename the target directory

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.

Option 2: rsync

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值