Skip to content

Instantly share code, notes, and snippets.

@kinncj
Created January 31, 2014 20:41
Show Gist options
  • Save kinncj/8742717 to your computer and use it in GitHub Desktop.
Save kinncj/8742717 to your computer and use it in GitHub Desktop.
pick.php
<?php
echo "\n--------------------------------------------------------------------------------------------------\n";
echo "| Git cherry-pick tool |";
echo "\n--------------------------------------------------------------------------------------------------\n";
if (empty($argv[1]) || empty($argv[2])) {
die("Usage: php pick.php [/git/repo/path] [hash]\n");
}
define("COMMIT_HASH", $argv[2]);
define("REPOSITORY", $argv[1]);
define("GIT_COMMAND", "git --git-dir=".REPOSITORY."/.git --work-tree=".REPOSITORY);
shell_exec("cd ".REPOSITORY);
$branchList = shell_exec(GIT_COMMAND." branch -r");
$branchList = trim(str_replace("origin/", "", $branchList));
$branchList = explode("\n", $branchList);
echo "\nCherry-picking from: ".COMMIT_HASH."\n";
foreach ($branchList as $branch) {
$branch = trim($branch);
if (strpos($branch, "->")) {
continue;
}
echo "Branch: {$branch}\n";
shell_exec(GIT_COMMAND." checkout {$branch}");
shell_exec(GIT_COMMAND." cherry-pick ".COMMIT_HASH);
shell_exec(GIT_COMMAND." push origin {$branch}");
echo "\n--------------------------------------------------------------------------------------------------\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment