Skip to content
This repository was archived by the owner on Mar 9, 2019. It is now read-only.

Commit a45f0ad

Browse files
committedMay 27, 2014
Updated comments
1 parent 18e7c8f commit a45f0ad

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed
 

‎git-amend-old

+9-7
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fi
1414
PREVBRANCH=$(git rev-parse --symbolic-full-name --abbrev-ref HEAD)
1515
TMPBRANCH="tmp-$(cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 16 | head -n 1)"
1616

17-
# 0 - Commit changes
17+
# Commit all staged changes
1818
if ! git commit -m "MERGE $TARGETHASH"
1919
then
2020
echo "Failed to commit changes. Did you forget to add them?"
@@ -23,19 +23,19 @@ fi
2323

2424
NEWCHANGES=$(git rev-parse HEAD)
2525

26-
# 1 - Stash any other changes
26+
# Stash any other changes
2727
DIRTYFILECOUNT=$(git status --porcelain 2>/dev/null| grep "^ M" | wc -l)
2828
[ $DIRTYFILECOUNT -ne 0 ] && git stash save --keep-index
2929

30-
# 2 - Switch to a temporary branch
30+
# Switch to a temporary branch
3131
if ! git checkout -b $TMPBRANCH
3232
then
3333
echo "Failed to checkout a temporary branch. Please check your repository's state and try again."
3434
[ $DIRTYFILECOUNT -ne 0 ] && git stash pop
3535
exit 1
3636
fi
3737

38-
# 3 - Rewind to the target commit
38+
# Rewind to the target commit
3939
if ! git reset --hard $TARGETHASH
4040
then
4141
echo "Failed to rewind to target commit."
@@ -45,7 +45,7 @@ if ! git reset --hard $TARGETHASH
4545
exit 1
4646
fi
4747

48-
# 4 - Stage changes
48+
# Use cherry-pick to stage the changes
4949
if ! git cherry-pick -n $NEWCHANGES
5050
then
5151
echo "Failed to apply new changes."
@@ -55,7 +55,7 @@ if ! git cherry-pick -n $NEWCHANGES
5555
exit 1
5656
fi
5757

58-
# 4 - Merge staged changes at this point
58+
# Merge staged changes at this point
5959
if ! git commit --amend
6060
then
6161
echo "Failed to merge changes into the target commit."
@@ -65,7 +65,7 @@ if ! git commit --amend
6565
exit 1
6666
fi
6767

68-
# 5 - Finally rebase
68+
# Finally we rebase to include the proceeding commits
6969
if ! git rebase --onto $TMPBRANCH HEAD@{1} $PREVBRANCH
7070
then
7171
echo "Failed to perform the final rebase."
@@ -75,9 +75,11 @@ if ! git rebase --onto $TMPBRANCH HEAD@{1} $PREVBRANCH
7575
exit 1
7676
fi
7777

78+
# Pop any uncommitted changes from the start
7879
[ $DIRTYFILECOUNT -ne 0 ] && git stash pop
7980
git branch -d $TMPBRANCH
8081

82+
# Great success!
8183
echo "Successfully merged changes with commit $TARGETHASH."
8284
exit 0
8385

0 commit comments

Comments
 (0)
This repository has been archived.