Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git: squash/fixup earlier commit

Tags:

Suppose you have:

A-B-C 

Now your build/test fails. The fix should be merged in A. My current work-flow is like this:

$ git commit -m "fixA"  A-B-C-fixA  $ git rebase -i A~1 

And squash fixA in A, result in:

A'-B-C 

Is there a command to do something like:

A-B-C + (index with fix for A)  $ git commit -supperdupper A  

Result:

A'-B-C 
like image 432
elmarco Avatar asked Oct 15 '08 12:10

elmarco


People also ask

How do I rebase fixup commits?

Creates a fixup commit that can be autosquashed in the next rebase. Use git commit --fixup <commit> to create a fixup commit for the specified <commit> . After running git rebase --autosquash , fixup commits will be automatically squashed into the commits they reference.

How do you manually commit squash?

In case you are using the Tower Git client, using Interactive Rebase to squash some commits is very simple: just select the commits you want to combine, right-click any of them, and select the "Squash Revisions..." option from the contextual menu.


1 Answers

If you're just looking for the easy solution for fixing up earlier commits, read the question! It explains it all. But since Elmarco was asking for a slick way, here we go:

As of Git 1.7.0, there is an --autosquash option for rebase, which does what you want. There is also the --fixup and --squash options for commit to make things easier. With some aliasing you can probably even get the whole thing into a single command.

I'd suggest upgrading to the newest Git for maximum awesomeness:

git/Documentation/RelNotes $ grep -i -A1 autosquash\\\|fixup * 1.7.0.txt: * "git rebase -i" learned new action "fixup" that squashes the change 1.7.0.txt-   but does not affect existing log message. -- 1.7.0.txt: * "git rebase -i" also learned --autosquash option that is useful 1.7.0.txt:   together with the new "fixup" action. 1.7.0.txt- -- 1.7.3.txt: * "git rebase -i" peeks into rebase.autosquash configuration and acts as 1.7.3.txt:   if you gave --autosquash from the command line. 1.7.3.txt- -- 1.7.4.txt: * "git commit" learned --fixup and --squash options to help later invocation 1.7.4.txt-   of the interactive rebase. -- 1.7.4.txt: * "git rebase --autosquash" can use SHA-1 object names to name which 1.7.4.txt:   commit to fix up (e.g. "fixup! e83c5163"). 1.7.4.txt- 
like image 102
Jo Liss Avatar answered Oct 03 '22 20:10

Jo Liss