Tôi đã tạo một tập lệnh php để xuất các tệp đã thay đổi trên Windows. Nếu bạn có một máy chủ phát triển localhost với php được thiết lập thì bạn có thể chạy nó một cách dễ dàng. Nó sẽ nhớ kho lưu trữ cuối cùng của bạn và xuất luôn vào cùng một thư mục. Thư mục xuất luôn được dọn sạch trước khi xuất. Bạn cũng sẽ thấy các tệp đã xóa màu đỏ để bạn biết những gì cần xóa trên máy chủ.
Đây chỉ là hai tệp để tôi sẽ đăng chúng ở đây. Giả sử các kho lưu trữ của bạn được đặt dưới thư mục c:/www trong các thư mục riêng của chúng và rằng http://localhost cũng trỏ tới c:/www và được bật php. Hãy đặt những 2 file trong c:/www/git khẩu -
index.php:
<?php
/* create directory if doesn't exist */
function createDir($dirName, $perm = 0777) {
$dirs = explode('/', $dirName);
$dir='';
foreach ($dirs as $part) {
$dir.=$part.'/';
if (!is_dir($dir) && strlen($dir)>0) {
mkdir($dir, $perm);
}
}
}
/* deletes dir recursevely, be careful! */
function deleteDirRecursive($f) {
if (strpos($f, "c:/www/export" . "/") !== 0) {
exit("deleteDirRecursive() protection disabled deleting of tree: $f - please edit the path check in source php file!");
}
if (is_dir($f)) {
foreach(scandir($f) as $item) {
if ($item == '.' || $item == '..') {
continue;
}
deleteDirRecursive($f . "/" . $item);
}
rmdir($f);
} elseif (is_file($f)) {
unlink($f);
}
}
$lastRepoDirFile = "last_repo_dir.txt";
$repo = isset($_POST['repo']) ? $_POST['repo'] : null;
if (!$repo && is_file($lastRepoDirFile)) {
$repo = file_get_contents($lastRepoDirFile);
}
$range = isset($_POST['range']) ? $_POST['range'] : "HEAD~1 HEAD";
$ini = parse_ini_file("git-export.ini");
$exportDir = $ini['export_dir'];
?>
<html>
<head>
<title>Git export changed files</title>
</head>
<body>
<form action="." method="post">
repository: <?=$ini['base_repo_dir'] ?>/<input type="text" name="repo" value="<?=htmlspecialchars($repo) ?>" size="25"><br/><br/>
range: <input type="text" name="range" value="<?=htmlspecialchars($range) ?>" size="100"><br/><br/>
target: <strong><?=$exportDir ?></strong><br/><br/>
<input type="submit" value="EXPORT!">
</form>
<br/>
<?php
if (!empty($_POST)) {
/* ************************************************************** */
file_put_contents($lastRepoDirFile, $repo);
$repoDir = $ini['base_repo_dir'] ."/$repo";
$repoDir = rtrim($repoDir, '/\\');
echo "<hr/>source repository: <strong>$repoDir</strong><br/>";
echo "exporting to: <strong>$exportDir</strong><br/><br/>\n";
createDir($exportDir);
// empty export dir
foreach (scandir($exportDir) as $file) {
if ($file != '..' && $file != '.') {
deleteDirRecursive("$exportDir/$file");
}
}
// execute git diff
$cmd = "git --git-dir=$repoDir/.git diff $range --name-only";
exec("$cmd 2>&1", $output, $err);
if ($err) {
echo "Command error: <br/>";
echo implode("<br/>", array_map('htmlspecialchars', $output));
exit;
}
// $output contains a list of filenames with paths of changed files
foreach ($output as $file) {
$source = "$repoDir/$file";
if (is_file($source)) {
if (strpos($file, '/')) {
createDir("$exportDir/" .dirname($file));
}
copy($source, "$exportDir/$file");
echo "$file<br/>\n";
} else {
// deleted file
echo "<span style='color: red'>$file</span><br/>\n";
}
}
}
?>
</body>
</html>
git-export.ini:
; path to all your git repositories for convenience - less typing
base_repo_dir = c:/www
; if you change it you have to also change it in the php script
; in deleteDirRecursive() function - this is for security
export_dir = c:/www/export
Và bây giờ tải localhost/git- xuất/trong trình duyệt. Tập lệnh được thiết lập để xuất luôn vào c:/www/export - thay đổi tất cả các đường dẫn cho phù hợp với môi trường của bạn hoặc sửa đổi kịch bản cho phù hợp với nhu cầu của bạn.
Điều này sẽ hoạt động nếu bạn đã cài đặt Git sao cho lệnh git nằm trong PATH của bạn - điều này có thể được định cấu hình khi bạn chạy trình cài đặt Git của Windows.
Nguồn
2011-01-06 02:38:04
Bây giờ tôi chỉ phải tìm ou một cách để dán kết quả của lệnh này với tar! Cảm ơn bạn! –
@Taverneiro Bạn có thể đặt nó vào lệnh [tar được đưa ra trong câu trả lời này] (http://stackoverflow.com/questions/2597875/how-can-i-build-a-tar-from-stdin), ví dụ: đối với tệp tgz: 'git diff-tree -r --no-cam-id - chỉ -name -diff-filter = ACMRT $ commit_id | tar -zf file.tgz -T -' –