{"thread":{"id":"22821","subject":"[RFC,PATCH] git-amend -- darcs like amend-record for git","startedAt":"2010-02-25T14:16:05Z","lastAt":"2010-03-03T08:01:14Z","messageCount":4,"participants":["Kirill Smelkov","Tay Ray Chuan","Larry D'Anna"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"135675","messageId":"1267107365-2973-1-git-send-email-kirr@mns.spb.ru","threadId":"22821","inReplyTo":null,"subject":"[RFC,PATCH] git-amend -- darcs like amend-record for git","fromName":"Kirill Smelkov","fromEmail":"kirr@mns.spb.ru","sentAt":"2010-02-25T14:16:05Z","receivedAt":"2010-02-25T14:16:05Z","isPatch":true,"sender":{"key":"kirr@navytux.spb.ru","avatar":"https://gravatar.com/avatar/cf3445fdad1849941e17ab25bf1ee7c5ea1be2deb444be25ff5f36b0e50a985f?d=mp&s=160"},"body":"Ever wanted to type `git commit --amend HEAD~3` ? But had to fall back to commit\nand interactive rebase with fixup? And was tired by a lot of typing? And also\nrebase works only on clean worktree, so stash save and stash pop have to be\nused...\n\nForget it.\n\nNow one can just do `git add ...` to prepare index, and then\n`git amend <commit>` to merge that changes from index into <commit>.\n\nYes, it uses rebase behind the scenes (or better sequencer, when it is\navailable), but the end result is less typing and much better usability for\nhumans. And it even tries to work in dirty worktree...\n\nSo operations like amending HEAD~3 take not significanltly more time, than\njust amending HEAD with already available `git commit --amend`.\n\nIt's only a prototype, without documentation and tests, just an RFC.\n\nIf you find the idea useful, please let me know. In case people want something\nlike this, I'll try to polish it for inclusion into git.\n\nThanks,\nKirill\n---\n contrib/git-amend.sh |   53 ++++++++++++++++++++++++++++++++++++++++++++++++++\n 1 files changed, 53 insertions(+), 0 deletions(-)\n create mode 100755 contrib/git-amend.sh\n\ndiff --git a/contrib/git-amend.sh b/contrib/git-amend.sh\nnew file mode 100755\nindex 0000000..1778594\n--- /dev/null\n+++ b/contrib/git-amend.sh\n@@ -0,0 +1,53 @@\n+#!/bin/sh -e\n+# git-amend: darcs like amend-record for git\n+# FIXME error handling\n+\n+USAGE=\"<commit>\"\n+. git-sh-setup\n+\n+test \"$#\" = 1 || usage\n+\n+commit=$1\n+\n+# let's see if $commit is a valid one, and also transform it to sha1 for it not\n+# to be dependant on current HEAD\n+commit=$(git rev-parse \"$commit\")\n+\n+# look out merges!\n+test -z \"$(git log --merges ${commit}~..HEAD)\" || \\\n+\tdie \"E: can't amend commits behind merges\"\n+\n+# commit index, allowing empty commit just for being able to amend patch\n+# description\n+git commit --allow-empty -m \"amend for $commit\"\n+\n+# save worktree/index state\n+work=$(git stash create)\n+test -n \"$work\" && git update-ref HEAD.amend-backup $work\n+\n+# reset to clean work/index before going into rebase\n+git reset --hard HEAD\n+\n+fixup_cmd=$(mktemp -t git-amend-fixupcmd.XXXXXX)\n+rest_cmd=$(mktemp -t git-amend-restcmd.XXXXXX)\n+trap 'rm -f \"$fixup_cmd\" \"$rest_cmd\"' 0\n+{\n+echo -ne \"pick\\t\";  git log --pretty=oneline -1 ${commit}\n+echo -ne \"fixup\\t\"; git log --pretty=oneline -1 ${HEAD}\n+} > \"$fixup_cmd\"\n+\n+git log --pretty=oneline --reverse ${commit}..HEAD~ | awk '{print \"pick\\t\" $0;}' \\\n+\t> \"$rest_cmd\"\n+\n+# now let's apply fixup part to commit\n+GIT_EDITOR=\"cat $fixup_cmd >\" git rebase -i ${commit}~\n+\n+# reword it\n+git commit -v --amend\n+\n+# and apply rest\n+GIT_EDITOR=\"cat $rest_cmd >\" git rebase -i HEAD\n+\n+\n+# restore worktree/index state\n+test -n \"$work\" && git stash apply --index $work\n-- \n1.7.0.91.g9803\n"},{"id":"135934","messageId":"be6fef0d1003010116p443985b3ib71f229a1978f831@mail.gmail.com","threadId":"22821","inReplyTo":"1267107365-2973-1-git-send-email-kirr@mns.spb.ru","subject":"Re: [RFC,PATCH] git-amend -- darcs like amend-record for git","fromName":"Tay Ray Chuan","fromEmail":"rctay89@gmail.com","sentAt":"2010-03-01T09:16:24Z","receivedAt":"2010-03-01T09:16:24Z","isPatch":true,"sender":{"key":"rctay89@gmail.com","avatar":"https://avatars.githubusercontent.com/u/61553?v=4"},"body":"Hi,\n\nOn Thu, Feb 25, 2010 at 10:16 PM, Kirill Smelkov <kirr@mns.spb.ru> wrote:\n> Ever wanted to type `git commit --amend HEAD~3` ? But had to fall back to commit\n> and interactive rebase with fixup? And was tired by a lot of typing? And also\n> rebase works only on clean worktree, so stash save and stash pop have to be\n> used...\n>\n> Forget it.\n>\n> Now one can just do `git add ...` to prepare index, and then\n> `git amend <commit>` to merge that changes from index into <commit>.\n\nthis may be a little late, but I'd like to indicate my interest in\nsuch a feature.\n\nA suggestion: I believe this could be better advertised as git-rebase\n--interactive --edit. After all, you do replay the intervening commits\n(which is closer to git-rebase than git-commit).\n\n-- \nCheers,\nRay Chuan\n"},{"id":"135957","messageId":"20100301170859.GA4142@cthulhu","threadId":"22821","inReplyTo":"be6fef0d1003010116p443985b3ib71f229a1978f831@mail.gmail.com","subject":"Re: [RFC,PATCH] git-amend -- darcs like amend-record for git","fromName":"Larry D'Anna","fromEmail":"larry@elder-gods.org","sentAt":"2010-03-01T17:08:59Z","receivedAt":"2010-03-01T17:08:59Z","isPatch":true,"sender":{"key":"larry@elder-gods.org","avatar":"https://avatars.githubusercontent.com/u/3013304?v=4"},"body":"* Tay Ray Chuan (rctay89@gmail.com) [100301 04:16]:\n> Hi,\n> \n> On Thu, Feb 25, 2010 at 10:16 PM, Kirill Smelkov <kirr@mns.spb.ru> wrote:\n> > Ever wanted to type `git commit --amend HEAD~3` ? But had to fall back to commit\n> > and interactive rebase with fixup? And was tired by a lot of typing? And also\n> > rebase works only on clean worktree, so stash save and stash pop have to be\n> > used...\n> >\n> > Forget it.\n> >\n> > Now one can just do `git add ...` to prepare index, and then\n> > `git amend <commit>` to merge that changes from index into <commit>.\n> \n> this may be a little late, but I'd like to indicate my interest in\n> such a feature.\n\nI like it too.\n\n  --larry\n"},{"id":"136064","messageId":"20100303080114.GB2919@tugrik.mns.mnsspb.ru","threadId":"22821","inReplyTo":"20100301170859.GA4142@cthulhu","subject":"Re: [RFC,PATCH] git-amend -- darcs like amend-record for git","fromName":"Kirill Smelkov","fromEmail":"kirr@mns.spb.ru","sentAt":"2010-03-03T08:01:14Z","receivedAt":"2010-03-03T08:01:14Z","isPatch":true,"sender":{"key":"kirr@navytux.spb.ru","avatar":"https://gravatar.com/avatar/cf3445fdad1849941e17ab25bf1ee7c5ea1be2deb444be25ff5f36b0e50a985f?d=mp&s=160"},"body":"On Mon, Mar 01, 2010 at 05:16:24PM +0800, Tay Ray Chuan wrote:\n> Hi,\n> \n> On Thu, Feb 25, 2010 at 10:16 PM, Kirill Smelkov <kirr@mns.spb.ru> wrote:\n> > Ever wanted to type `git commit --amend HEAD~3` ? But had to fall back to commit\n> > and interactive rebase with fixup? And was tired by a lot of typing? And also\n> > rebase works only on clean worktree, so stash save and stash pop have to be\n> > used...\n> >\n> > Forget it.\n> >\n> > Now one can just do `git add ...` to prepare index, and then\n> > `git amend <commit>` to merge that changes from index into <commit>.\n> \n> this may be a little late, but I'd like to indicate my interest in\n> such a feature.\n\nOn Mon, Mar 01, 2010 at 12:08:59PM -0500, Larry D'Anna wrote:\n> I like it too.\n\n\nTay Ray, Larry, thanks for the feedback.\n\nNow since it's obvious that at least some people need it too, I'll try\nto polish it. In the meantime, latest version is always available at\n\n    git://repo.or.cz/git/kirr.git   q/git-amend\n\n\nBut I'm short on spare time, so don't expect something fast...\n\n> A suggestion: I believe this could be better advertised as git-rebase\n> --interactive --edit. After all, you do replay the intervening commits\n> (which is closer to git-rebase than git-commit).\n\nThanks.\n\nYes, I do replay commits, but is it really a rebase? And also as to\n--edit thing - amending commits description is very handy, but is really\njust a nice artifact :).\n\nWhat I think is really important (in at least my workflow) is to prepare\nchanges in index, and then _merge_ them back to HEAD~2, i.e. not the\nlatest commit.\n\nI don't need this often, but sometimes I do, and in such cases `git\namend` is right tool for the job.\n\nThat's why I still think git-amend is maybe a better name.\n\nThough, I've found I'm now less reluctant to improving commit\ndescriptions as well, and exactly because of that nice --edit artifact\nbehaviour :)\n\n\n\nAs to the merging, the only a bit unclear moment to me, is to how\nproperly handle merge conflicts, when propagating index back to HEAD~2.\n\n\nKirill\n"}]}