git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* Pushing an --amend-ed commit
@ 2008-06-02  9:51 Robert Haines
  2008-06-02 14:55 ` Pushing an --amend-ed commit [and a git-merge-theirs strategy] Paolo Bonzini
  2008-06-03  0:08 ` Pushing an --amend-ed commit Matt Pearson
  0 siblings, 2 replies; 5+ messages in thread
From: Robert Haines @ 2008-06-02  9:51 UTC (permalink / raw)
  To: Git Mailing List

Hi list,

The other day I did the classic:

1) Right, changes all done and committed. Push to public repo.
2) Bugger, missed out an obvious one-liner in a Makefile. Make change  
and --amend that last commit.
3) Push to public repo again... Ah, "Not a strict subset" error, can't  
push...

It's obvious (I think) to me why I get this error - the commit now has  
a different hash so it looks like it would be the wrong thing to do to  
allow the push as far as git is concerned. Right?

So, is it safe to "use the --force" in this instance when pushing?  
This should just replace the old commit with the --amended commit with  
no side-effects, shouldn't it?

Thanks,
Rob

-- 
Robert Haines

Research Associate, RealityGrid          Tel. : +44 (0)161 275 6067
Research Computing Services              Fax. : +44 (0)161 275 0637
University of Manchester                 Email: rhaines@manchester.ac.uk
Oxford Road                              Web  : www.realitygrid.org
Manchester, M13 9PL, UK                       : www.rcs.manchester.ac.uk

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Pushing an --amend-ed commit [and a git-merge-theirs strategy]
  2008-06-02  9:51 Pushing an --amend-ed commit Robert Haines
@ 2008-06-02 14:55 ` Paolo Bonzini
  2008-06-03 17:49   ` Robert Haines
  2008-06-03  0:08 ` Pushing an --amend-ed commit Matt Pearson
  1 sibling, 1 reply; 5+ messages in thread
From: Paolo Bonzini @ 2008-06-02 14:55 UTC (permalink / raw)
  To: Robert Haines; +Cc: Git Mailing List


> 1) Right, changes all done and committed. Push to public repo.
> 2) Bugger, missed out an obvious one-liner in a Makefile. Make change 
> and --amend that last commit.
> 3) Push to public repo again... Ah, "Not a strict subset" error, can't 
> push...
> 
> It's obvious (I think) to me why I get this error - the commit now has a 
> different hash so it looks like it would be the wrong thing to do to 
> allow the push as far as git is concerned. Right?
> 
> So, is it safe to "use the --force" in this instance when pushing? This 
> should just replace the old commit with the --amended commit with no 
> side-effects, shouldn't it?

Yes, but it would screw up other people that pulled from you.

If that's an issue (it most likely is, unless you're just pushing just 
to your own mirror repository), it is better if you do it the other way 
round: adding your commits on top of origin^, starting from the one that 
fixed a typo.  In other words, make the history look like you hadn't 
used --amend.

Do like this: first create git-merge-theirs somewhere in your path; it's 
this three-line script, and it has to have that name.

#! /bin/sh
eval git reset \$$# -- .
git-checkout-index -q -f -a

Don't forget to make it executable. :-)

And here's the magic incantation to be executed on branch master:

git rebase -s theirs --onto origin/master origin/master^ HEAD

Basically, it uses the script created above to place the commits _after_ 
origin/master^ _above_ origin/master.  What the script does is resolve 
conflicts by taking the version in your "master" branch.

To do so, git-merge-theirs uses "git reset" to check out into the index 
the last head passed to it (which we know is the next commit being added 
to the rebase).  Then it extracts the index into the working tree to 
avoid complaints from "git commit" about files not being up-to-date.

There is no builtin git-merge-theirs strategy; if there was one, it 
should make sure that it was only called with two heads, for example.

Anyway, now you can push again.  I suggest however reviewing your commit 
messages and, if necessary, using "git rebase -i origin/master" to edit 
some of them.

Paolo

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Pushing an --amend-ed commit
  2008-06-02  9:51 Pushing an --amend-ed commit Robert Haines
  2008-06-02 14:55 ` Pushing an --amend-ed commit [and a git-merge-theirs strategy] Paolo Bonzini
@ 2008-06-03  0:08 ` Matt Pearson
  2008-06-03  0:22   ` Matt Pearson
  1 sibling, 1 reply; 5+ messages in thread
From: Matt Pearson @ 2008-06-03  0:08 UTC (permalink / raw)
  To: Robert Haines; +Cc: Git Mailing List

On Mon, Jun 2, 2008 at 5:51 AM, Robert Haines <rhaines@manchester.ac.uk> wrote:
> So, is it safe to "use the --force" in this instance when pushing? This
> should just replace the old commit with the --amended commit with no
> side-effects, shouldn't it?

Safe from what perspective?  If you're sure nobody has pulled from
you, then yes, it's fine.  If you know exactly who pulled and can
contact them to do a reset and re-pull, then it should be fine. If you
don't care about screwing up people who pulled from you, then I
suppose that's still fine.  However, screwing with history is
generally a bad idea, since now people who pull from you don't have
your current HEAD as a parent commit in their tree.  Finding common
ancestors is going to be messed up (and future merges with them,
possibly).

(also, first git mailing list post.  I hope none of the experienced
people have to correct me)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Pushing an --amend-ed commit
  2008-06-03  0:08 ` Pushing an --amend-ed commit Matt Pearson
@ 2008-06-03  0:22   ` Matt Pearson
  0 siblings, 0 replies; 5+ messages in thread
From: Matt Pearson @ 2008-06-03  0:22 UTC (permalink / raw)
  To: Robert Haines; +Cc: Git Mailing List

On Mon, Jun 2, 2008 at 8:08 PM, Matt Pearson <404emailnotfound@gmail.com> wrote:
> (also, first git mailing list post.  I hope none of the experienced
> people have to correct me)

Heh, guess I have to correct myself -- someone already replied a long
time ago.  That's what I get for replying right when I start reading
backlog and depending on gmail to group threads for me :)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Pushing an --amend-ed commit [and a git-merge-theirs strategy]
  2008-06-02 14:55 ` Pushing an --amend-ed commit [and a git-merge-theirs strategy] Paolo Bonzini
@ 2008-06-03 17:49   ` Robert Haines
  0 siblings, 0 replies; 5+ messages in thread
From: Robert Haines @ 2008-06-03 17:49 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: Git Mailing List

On 2 Jun 2008, at 15:55, Paolo Bonzini wrote:
>> 1) Right, changes all done and committed. Push to public repo.
>> 2) Bugger, missed out an obvious one-liner in a Makefile. Make  
>> change and --amend that last commit.
>> 3) Push to public repo again... Ah, "Not a strict subset" error,  
>> can't push...
>> It's obvious (I think) to me why I get this error - the commit now  
>> has a different hash so it looks like it would be the wrong thing  
>> to do to allow the push as far as git is concerned. Right?
>> So, is it safe to "use the --force" in this instance when pushing?  
>> This should just replace the old commit with the --amended commit  
>> with no side-effects, shouldn't it?
>
> Yes, but it would screw up other people that pulled from you.

Ah yes, forgot about that...

> If that's an issue (it most likely is, unless you're just pushing  
> just to your own mirror repository)

It's not an issue right now as I'm still experimenting, but it  
certainly will be when I let others lose on this stuff. It's really  
not something I see myself doing a lot - I usually test a lot more  
thoroughly before publishing to a public repo...

> it is better if you do it the other way round: adding your commits  
> on top of origin^, starting from the one that fixed a typo.  In  
> other words, make the history look like you hadn't used --amend.

<snip big explanation and code>

Thanks very much for the code and method. It goes over my head a bit  
right now, but I'll think on it and try it and see how I get on! A lot  
of what git can do scares me a bit still - mainly because it's me  
driving it...

Thanks also to the other people who answered me!

Cheers,
Rob

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-06-03 17:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-06-02  9:51 Pushing an --amend-ed commit Robert Haines
2008-06-02 14:55 ` Pushing an --amend-ed commit [and a git-merge-theirs strategy] Paolo Bonzini
2008-06-03 17:49   ` Robert Haines
2008-06-03  0:08 ` Pushing an --amend-ed commit Matt Pearson
2008-06-03  0:22   ` Matt Pearson

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).