问题描述
我正在开发一款PAAS应用程序。我们提供了GIT部署功能,我们从临时目录中的Git仓库中提取代码,并将数据复制到服务器的工作公共目录。
这种方法的问题它不会从Git Repo中删除直接工作的公共文件。我看到像DeployHQ这样的应用程序以某种方式从Git提交中提取该列表。
我是否必须解析Git历史记录或者是否有任何开源工具提取已删除列表/修改了Git提交历史记录中的文件。
这不一定是Git问题,但更多的是如何复制档案结束。如果您使用简单的 cp
命令,它不会删除源文件夹中已删除的任何文件,它只会复制任何新文件或更新文件。您的目标目录仍将包含在源文件夹中删除的文件。
以下是两种方法:
选项1:重命名目标目录
您基本上将文件从Git仓库复制到新的空目录。然后,您删除以前的目标文件夹并将新文件夹重命名为公用文件夹:
cp -r git_repo / * temp
rm -rf public
mv temp public
这会让你做一个干净的打破,因为您使用 mv
命令切换目录。此时,新文件夹将变为活动状态。您可能会遇到问题,如果一个进程保持文件引用在旧文件夹中打开。
选项2:rsync
不要使用 cp
命令,你可以使用类似于 rsync
的东西,这将允许你复制更改,也删除不再存在的文件。查看 rsync
手册页以获取更多信息和示例:
下面是一个启动的例子:
rsync -avrKL --progress -d --delete-excluded --exclude = .git git_repo / public /
rsync
的一个优点是它非常高效 - 它不会复制任何未更改文件。一旦你完成了第一次运行,它只会复制更改,新文件或删除已删除的文件,其他所有内容都将被保留。
$ c> rsync 是您可以使用 - exlude
开关自定义它的复制内容。以类似的方式,您可以使用 - 包含
开关以通配符模式。
确保文件被删除在源文件夹中从目标文件夹中删除,请确保在 rsync
命令行中的源文件夹末尾使用斜杠。这会告诉 rsync
来同步整个文件夹。
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.
这篇关于从Git提交中获取已删除的文件列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!