lilypond-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: accidental reverts in git


From: David Kastrup
Subject: Re: accidental reverts in git
Date: Fri, 11 Jul 2014 18:42:24 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4.50 (gnu/linux)

Mark Polesky <address@hidden> writes:

> In response to http://code.google.com/p/lilypond/issues/detail?id=3952#c7
>
> David, here's a simplified version of the faulty workflow.
> The problem occurs in step 5 where I accidentally did
> `HEAD..bar' instead of `master..bar' (thinko).

> 1) git log --graph --all --decorate --oneline | cat
>
> * a9af02f (bar) Finish fixing bar.
> * d3b60de Start fixing bar.
> | * 38e720f (foo) Fix foo.
> |/
> * 9491de4 (HEAD, staging, master) HEAD of master branch.
>
> 2) git co staging
> 3) git cherry-pick foo
> 4) git log --graph --all --decorate --oneline | cat
>
> * c7b770d (HEAD, staging) Fix foo.
> | * a9af02f (bar) Finish fixing bar.
> | * d3b60de Start fixing bar.
> |/
> | * 38e720f (foo) Fix foo.
> |/
> * 9491de4 (master) HEAD of master branch.
>
> 5) git diff HEAD..bar > patch0.patch
> 6) git apply patch0.patch
> 7) git commit -am"Fix bar."

No.  No, no, no.  _Never_ convert anything into a patch which you then
apply.  You lose all context, and Git loses all context, patch authors,
patch dates etc.  If you do "git reflog", you cannot reconstruct what
happened as the source of the basically anonymous patch is opaque.

If you want to squash a sequence of commits into a single commit, use
"git rebase -i" instead.  In this case,

    git rebase -i master

Assuming that your EDITOR variable points to an editor you can handle,
it will be self-evident how to go from there (basically, you want to
"squash" all commits into a single one, or perhaps several ones after
reordering them).

After properly rearranging your branch, you can then push it.

Conversion into a patch will make Git lose all context and all clues for
conflict resolution.  And, of course, you can get some changes in that
do not correspond to the commits which you see/combine in your history.

git apply basically is _only_ for patches sent by someone else as patch,
and even then you are usually better off by asking for the result of
"git format-patch" which you can then apply using "git am" and thus get
all the commit message and metadata.

Really, try getting acquainted with git rebase -i: it is a very powerful
tool for rearranging history.

-- 
David Kastrup



reply via email to

[Prev in Thread] Current Thread [Next in Thread]