threads / discuss / 19286

merging multiple commit into one?

Subject: merging multiple commit into one?

## tl;dr

10 messages between May 11, 2009 and May 12, 2009.

replies: 9people: 5as markdown or json

jean-luc malet· May 11, 2009, 13:21 UTC · lore

Hi, I often commit "useless" code, for example before going into weekend or for saving some state during a dev process often thoses commit are simply useless and the commit message looks like "COMPILE ERROR - temporary save .... " at the end I have LOT of theses commits that are useless and I want to save some space/time/tree complexity merge multiple sequential commits (without branch) into one is it possible? according to my knowledge of git, removing the commit and rewriting the last commit log so that it better reflect the modification will do the job but I'm not sure git allow it... thanks JLM

-- 
KISS! (Keep It Simple, Stupid!)
(garde le simple, imbécile!)
"mais qu'est-ce que tu m'as pondu comme usine à gaz? fait des choses
simples et qui marchent, espèce d'imbécile!"
-----------------------------
"Si vous pensez que vous êtes trop petit pour changer quoique ce soit,
essayez donc de dormir avec un moustique dans votre chambre." Betty
Reese
http://www.grainesdechangement.com/citations.htm
Andreas Ericsson· May 11, 2009, 13:31 UTC · re: jean-luc malet · lore

Re: merging multiple commit into one?

jean-luc malet wrote:
Show 13 quoted lines
> Hi,
> I often commit "useless" code, for example before going into weekend
> or for saving some state during a dev process
> often thoses commit are simply useless and the commit message looks
> like "COMPILE ERROR - temporary save .... "
> at the end I have LOT of theses commits that are useless and I want to
> save some space/time/tree complexity merge multiple sequential commits
> (without branch) into one
> is it possible?
> according to my knowledge of git, removing the commit and rewriting
> the last commit log so that it better reflect the modification will do
> the job but I'm not sure git allow it...
> thanks

git commit --amend; # to extend last commit only git merge --squash; # I think. Not sure though, so read the docs git rebase -i; # replace "pick" with "squash" to combine commits.

-- 
Andreas Ericsson                   andreas.ericsson@op5.se
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231

Register now for Nordic Meet on Nagios, June 3-4 in Stockholm
 http://nordicmeetonnagios.op5.org/

Considering the successes of the wars on alcohol, poverty, drugs and
terror, I think we should give some serious thought to declaring war
on peace.
Jakub Narebski· May 11, 2009, 13:50 UTC · re: jean-luc malet · lore

Re: merging multiple commit into one?

jean-luc malet <jeanluc.malet@gmail.com> writes:
Show 9 quoted lines
> Hi,
> I often commit "useless" code, for example before going into weekend
> or for saving some state during a dev process
> often thoses commit are simply useless and the commit message looks
> like "COMPILE ERROR - temporary save .... "
> at the end I have LOT of theses commits that are useless and I want to
> save some space/time/tree complexity merge multiple sequential commits
> (without branch) into one
> is it possible?

It is possible; one solution would be to use "git rebase --interactive" and its 'squash' command...

> according to my knowledge of git, removing the commit and rewriting
> the last commit log so that it better reflect the modification will do
> the job but I'm not sure git allow it...

...but you can simply pick up where you saved snapshot by using "git commit --amend" (or doing soft or mixed reset to previous commit before comitting changes).

-- 
Jakub Narebski
Poland
ShadeHawk on #git
MALET Jean-Luc· May 11, 2009, 22:11 UTC · re: Jakub Narebski · lore

Re: merging multiple commit into one?

Jakub Narebski wrote:
Show 28 quoted lines
> jean-luc malet <jeanluc.malet@gmail.com> writes:
>
>   
>> Hi,
>> I often commit "useless" code, for example before going into weekend
>> or for saving some state during a dev process
>> often thoses commit are simply useless and the commit message looks
>> like "COMPILE ERROR - temporary save .... "
>> at the end I have LOT of theses commits that are useless and I want to
>> save some space/time/tree complexity merge multiple sequential commits
>> (without branch) into one
>> is it possible?
>>     
>
> It is possible; one solution would be to use "git rebase --interactive"
> and its 'squash' command...
>
>   
>> according to my knowledge of git, removing the commit and rewriting
>> the last commit log so that it better reflect the modification will do
>> the job but I'm not sure git allow it...
>>     
>
> ...but you can simply pick up where you saved snapshot by using "git
> commit --amend" (or doing soft or mixed reset to previous commit
> before comitting changes).
>
>   
hi! thanks for your answers!
I didn't knew about --amend for commit, will certainly use it...
however it seems that I get missunderstood...
A-o-o-o-o-o-B-o-o-o-o-C
                      \-o-o-D-/
let say I have the above tree, o are temporary unbuildable commits, A B 
C D are usable versions
I want as posteriory remove the o to get the following tree
A-B---C
     \-D/
in fact I just wanna clean a little my tree since I forgot to amend ;)
is this possible?
ok I know, the best is to prevent! not to cure! so I'll amend ;)
thanks
JLM
Jakub Narebski· May 11, 2009, 22:36 UTC · re: MALET Jean-Luc · lore

Re: merging multiple commit into one?

On Tue, 12 May 2009, MALET Jean-Luc wrote:
> Jakub Narebski wrote:
>> jean-luc malet <jeanluc.malet@gmail.com> writes:
Show 8 quoted lines
>>> I often commit "useless" code, for example before going into weekend
>>> or for saving some state during a dev process
>>> often thoses commit are simply useless and the commit message looks
>>> like "COMPILE ERROR - temporary save .... "
>>> at the end I have LOT of theses commits that are useless and I want to
>>> save some space/time/tree complexity merge multiple sequential commits
>>> (without branch) into one
>>> is it possible?
>>
>> It is possible; one solution would be to use "git rebase --interactive"
>> and its 'squash' command...
   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   
Show 23 quoted lines
>>> according to my knowledge of git, removing the commit and rewriting
>>> the last commit log so that it better reflect the modification will do
>>> the job but I'm not sure git allow it...
>>>     
>>
>> ...but you can simply pick up where you saved snapshot by using "git
>> commit --amend" (or doing soft or mixed reset to previous commit
>> before comitting changes).
>>
>>   
> hi! thanks for your answers!
> I didn't knew about --amend for commit, will certainly use it...
> however it seems that I get missunderstood...
> A-o-o-o-o-o-B-o-o-o-o-C
>                       \-o-o-D-/
> let say I have the above tree, o are temporary unbuildable commits, A B 
> C D are usable versions
> I want as posteriory remove the o to get the following tree
> A-B---C
>      \-D/
> in fact I just wanna clean a little my tree since I forgot to amend ;)
> is this possible?
> ok I know, the best is to prevent! not to cure! so I'll amend ;)
As I wrote above, you can use interactive rebase to clean up history.
-- 
Jakub Narebski
Poland
jean-luc malet· May 12, 2009, 15:59 UTC · re: Jakub Narebski · lore

Re: merging multiple commit into one?

hello seems that I don't use the right way.... I chechouted my lastest branch, then do a git rebase --interactive 9ce8f6940a50d87e4f6503ff237bd1b1ff560660 where 9ce8f6940a50d87e4f6503ff237bd1b1ff560660 is the commit I want to start... I modified the file and marked the commit I wanted to squash... and well it keep continue to find me conflicts.... even where there shall not be

so I said I have to start from the root and rebase my branch on it.... created a branch on root, checkout it, git rebase --interactive b52ea8c36188b05de246d5717781ab90710078d5 huh?! nothing to do... ok fine

so I tried to put branch just after the nodes I wanted to squash.... and git rebase --interactive thesha1rigthbeforewhatiwantedtosquash.... ah! here it works! huh?! well quite not! it replayed the range of commit fine, removed the squashed one... fine... but do created another independant branch... what I don't want I just want to remove a set inside the current tree so I'm not doing it right?

thanks JLM

On Tue, May 12, 2009 at 12:36 AM, Jakub Narebski <jnareb@gmail.com> wrote:
Show 49 quoted lines
> On Tue, 12 May 2009, MALET Jean-Luc wrote:
>> Jakub Narebski wrote:
>>> jean-luc malet <jeanluc.malet@gmail.com> writes:
>
>>>> I often commit "useless" code, for example before going into weekend
>>>> or for saving some state during a dev process
>>>> often thoses commit are simply useless and the commit message looks
>>>> like "COMPILE ERROR - temporary save .... "
>>>> at the end I have LOT of theses commits that are useless and I want to
>>>> save some space/time/tree complexity merge multiple sequential commits
>>>> (without branch) into one
>>>> is it possible?
>
>>>
>>> It is possible; one solution would be to use "git rebase --interactive"
>>> and its 'squash' command...
>
>   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>
>>>> according to my knowledge of git, removing the commit and rewriting
>>>> the last commit log so that it better reflect the modification will do
>>>> the job but I'm not sure git allow it...
>>>>
>>>
>>> ...but you can simply pick up where you saved snapshot by using "git
>>> commit --amend" (or doing soft or mixed reset to previous commit
>>> before comitting changes).
>>>
>>>
>> hi! thanks for your answers!
>> I didn't knew about --amend for commit, will certainly use it...
>> however it seems that I get missunderstood...
>> A-o-o-o-o-o-B-o-o-o-o-C
>>                       \-o-o-D-/
>> let say I have the above tree, o are temporary unbuildable commits, A B
>> C D are usable versions
>> I want as posteriory remove the o to get the following tree
>> A-B---C
>>      \-D/
>> in fact I just wanna clean a little my tree since I forgot to amend ;)
>> is this possible?
>> ok I know, the best is to prevent! not to cure! so I'll amend ;)
>
> As I wrote above, you can use interactive rebase to clean up history.
>
> --
> Jakub Narebski
> Poland
>
-- 
KISS! (Keep It Simple, Stupid!)
(garde le simple, imbécile!)
"mais qu'est-ce que tu m'as pondu comme usine à gaz? fait des choses
simples et qui marchent, espèce d'imbécile!"
-----------------------------
"Si vous pensez que vous êtes trop petit pour changer quoique ce soit,
essayez donc de dormir avec un moustique dans votre chambre." Betty
Reese
http://www.grainesdechangement.com/citations.htm
Heiko Voigt· May 11, 2009, 21:29 UTC · re: jean-luc malet · lore

Re: merging multiple commit into one?

On Mon, May 11, 2009 at 03:21:27PM +0200, jean-luc malet wrote:
> according to my knowledge of git, removing the commit and rewriting
> the last commit log so that it better reflect the modification will do
> the job but I'm not sure git allow it...
If you just want to get rid of the last commit
  git reset HEAD^

will remove the commit but keep your working directory untouched. In such a workflow I find it easier to start the new commit from zero than from the stashed stuff.

By the way. You might also take a look at the command
  git stash
which is especially crafted for saving work in progress.
cheers Heiko
MALET Jean-Luc· May 11, 2009, 22:11 UTC · re: Heiko Voigt · lore

Re: merging multiple commit into one?

Heiko Voigt wrote:
Show 23 quoted lines
> On Mon, May 11, 2009 at 03:21:27PM +0200, jean-luc malet wrote:
>   
>> according to my knowledge of git, removing the commit and rewriting
>> the last commit log so that it better reflect the modification will do
>> the job but I'm not sure git allow it...
>>     
>
> If you just want to get rid of the last commit
>
>   git reset HEAD^
>
> will remove the commit but keep your working directory untouched. In
> such a workflow I find it easier to start the new commit from zero than
> from the stashed stuff.
>
> By the way. You might also take a look at the command
>
>   git stash
>
> which is especially crafted for saving work in progress.
>
> cheers Heiko
>   

hi, thanks, I know about git stash, the problem is that this command don't fits well when working on multiple copies of the sources on different locations, git stash is usefull for saving states before branching elsewhere and comming back to the branch and keep going on your work.... I use it in a different way since I commit to continue work on a different pc, (so I commit, I push to some git archive, I pull from the other pc, and continue the work on the other pc, then commit push again and pull again on first pc....). As far as I know you can't push stashed information, I'm wrong? thanks JLM

Heiko Voigt· May 12, 2009, 15:53 UTC · re: MALET Jean-Luc · lore

Re: merging multiple commit into one?

On Tue, May 12, 2009 at 12:11:24AM +0200, MALET Jean-Luc wrote:
Show 10 quoted lines
> hi,
> thanks, I know about git stash, the problem is that this command don't  
> fits well when working on multiple copies of the sources on different  
> locations, git stash is usefull for saving states before branching  
> elsewhere and comming back to the branch and keep going on your work....  
> I use it in a different way since I  commit to continue work on a  
> different pc, (so I commit, I push to some git archive, I pull from the  
> other pc, and continue the work on the other pc, then commit push again  
> and pull again on first pc....). As far as I know you can't push stashed  
> information, I'm wrong?

AFAIR, git stash cannot be pushed. Well you could by creating a branch and pushing that but thats not native stash functionality.

cheers Heiko
Markus Heidelberg· May 12, 2009, 20:37 UTC · re: Heiko Voigt · lore

Re: merging multiple commit into one?

Heiko Voigt, 12.05.2009:
Show 6 quoted lines
> On Tue, May 12, 2009 at 12:11:24AM +0200, MALET Jean-Luc wrote:
> > As far as I know you can't push stashed  
> > information, I'm wrong?
> 
> AFAIR, git stash cannot be pushed. Well you could by creating a branch
> and pushing that but thats not native stash functionality.

I tried "git clone --mirror" with a repo containing a stash, the clone had a stash entry in .git/packed-refs. "git push --mirror" didn't work, though. Not sure what should be intended.

Markus

← back to recent threads