Skip to Content.
Sympa Menu

sm-discuss - [SM-Discuss] git: cherry-pick whole directories

sm-discuss AT lists.ibiblio.org

Subject: Public SourceMage Discussion List

List archive

Chronological Thread  
  • From: Jaka Kranjc <lynx AT mages.ath.cx>
  • To: sm-discuss AT lists.ibiblio.org
  • Subject: [SM-Discuss] git: cherry-pick whole directories
  • Date: Mon, 22 Jan 2007 00:06:14 +0100

Today I needed this p4 integration functionality too (and someone was
bickering again), so after many git resets, here it is, a wrapper script that
does just that in git. It takes a path argument and optionally an "upstream"
branch. It is not interactive, but there is a slightly more powerful
interactive version cat at the end, double commented.

I'll add it to the wiki tommorow. Comments?

#START
# cd yourself to your git repo
# and checkout the target branch

path=$1
master=${2:-master}
[[ -e $path ]] || { echo bad path: $path; exit 1; }

cur_commits=$(git log --pretty=one-line -- $path | cut -d" " -f1)
git log --pretty=one-line $master -- $path |
cut -d" " -f1 |
tac |
while read commit; do
if ! grep -q $commit <<< "$cur_commits"; then
echo $commit
fi
done |
while read commit; do
git-cherry-pick $commit
done
#END

# # # cd yourself to your git repo
# # # and checkout the target branch
# #
# # path=$1
# # master=${2:-master}
# # [[ -e $path ]] || { echo bad path; exit 1; }
# #
# # git log $path
# # # get the starting commit id with
# # while [[ -z $starting_commit ]]; do
# # git log $master -- $path
# # echo
# # read -p "Which is the starting commit of the pick? " starting_commit
# # done
# #
# # git log --pretty=one-line $master -- $path |
# # sed -n "1,/$starting_commit/ s,^\(\S*\).*$,\1,p" |
# # tac |
# # while read commit; do
# # git-cherry-pick $commit || {
# # echo
# # echo fix the conflict, then restart me with the next commit after
$commit
# # exit 123; }
# # done

EXAMPLE:
navaden@lynxlynx git $ ../dir-cherry-pick x11-libs/wine
First trying simple merge strategy to cherry-pick.
Finished one cherry-pick.
First trying simple merge strategy to cherry-pick.
Finished one cherry-pick.
First trying simple merge strategy to cherry-pick.
Finished one cherry-pick.
First trying simple merge strategy to cherry-pick.
Finished one cherry-pick.
First trying simple merge strategy to cherry-pick.
Finished one cherry-pick.
First trying simple merge strategy to cherry-pick.
Finished one cherry-pick.
First trying simple merge strategy to cherry-pick.
Finished one cherry-pick.
First trying simple merge strategy to cherry-pick.
Finished one cherry-pick.
navaden@lynxlynx git $

--
We cannot command nature except by obeying her. --Sir Francis Bacon
Have a sourcerous day! www.sourcemage.org

Attachment: pgpHs6p7eMB3Q.pgp
Description: PGP signature




Archive powered by MHonArc 2.6.24.

Top of Page