Re: "git revert" (Re: pci_update_resource() getting called on sparc64)

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: "git revert" (Re: pci_update_resource() getting called on sparc64)

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:42:03

Linus Torvalds [off-list ref] writes:
quoted
It may not have the nicest error messages: if you try to revert a merge
(which won't have a diff), git-apply will say something like

	fatal: No changes

which isn't exactly being helpful. And the revert message could be made 
more interesting (like putting the first line of the description of what 
we reverted into the message instead of just the revision number).
Comments?

		Linus
I like the general idea, and if we had a commit pretty format
"oneline", then something like this would make it look nicer.

Totally untested.  I acquired your habit of coding in my e-mail
client ;-).

        #!/bin/sh
        . git-sh-setup-script || die "Not a git archive"

        rev=$(git-rev-parse --verify --revs-only "$@") &&
        commit=$(git-rev-parse --verify --revs-only "$commit^0") || exit
        if git-diff-tree -R -p $commit | git-apply --index &&
           msg=$(git-rev-list --pretty=oneline --max-count=1 $commit)
        then
                {
                        echo "Revert $msg"
                        echo
                        echo "This reverts $commit commit."
                        test "$rev" = "$commit" ||
                        echo "(original 'git revert' arguments: $@)"
                } | git commit
        else
                # Now why did it fail?
                parents=`git-cat-file commit "$commit" 2>/dev/null |
                        sed -ne '/^$/q;/^parent /p' |
                        wc -l`
                case $parents in
                0) die "Cannot revert the root commit nor non commit-ish" ;;
                1) die "The patch does not apply" ;;
                *) die "Cannot revert a merge commit" ;;
                esac
        fi

Re: "git revert" (Re: pci_update_resource() getting called on sparc64)

From: Linus Torvalds <torvalds@osdl.org>
Date: 2016-06-15 22:42:03


On Mon, 8 Aug 2005, Junio C Hamano wrote:
Totally untested.  I acquired your habit of coding in my e-mail
client ;-).
Looks good. Although I also have this advanced testing habit of just 
reading the email and if it looks sane it tested out ok ;)

But it strikes me that we could use the "-M" flag to git-diff-tree, which
makes it a lot more likely that we can revert renames, even if the file
has been slightly changed afterwards.

			Linus
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help