Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EGit / JGit » How do I squash commits?(question)
How do I squash commits? [message #989644] Fri, 07 December 2012 07:57 Go to next message
Tal Weiss is currently offline Tal WeissFriend
Messages: 4
Registered: October 2011
Junior Member
Is there a way to squash commits?
It is part of my regular workflow in git rebase -i
I have many junk temp commits which I don't want to push to Origin.

Thanks,

Tal.
Re: How do I squash commits? [message #989661 is a reply to message #989644] Fri, 07 December 2012 08:45 Go to previous messageGo to next message
Matthias Sohn is currently offline Matthias SohnFriend
Messages: 1268
Registered: July 2009
Senior Member
You may use soft reset to implement squashing with EGit
Re: How do I squash commits? [message #989663 is a reply to message #989644] Fri, 07 December 2012 08:48 Go to previous messageGo to next message
Christian Halstrick is currently offline Christian HalstrickFriend
Messages: 274
Registered: July 2009
Senior Member
If I want to squash the last m commits on the current branch the I
- select in history the first commit which I don't want to squash
- right-click and say "Team->Reset->Soft"
- right-click and say "Commit". This commit will contain all the changes of the last m commits together

It's more complicated when you want to squash together all commits between HEAD~6 and HEAD~2. And even more complicate if you want to squash HEAD~4 together with HEAD~2.


Ciao
Chris
Re: How do I squash commits? [message #989787 is a reply to message #989663] Fri, 07 December 2012 18:56 Go to previous messageGo to next message
Tal Weiss is currently offline Tal WeissFriend
Messages: 4
Registered: October 2011
Junior Member
Hmmm. Interesting.
Is there a way to concatenate my commit comments (as in Rebase Interactive)?
Re: How do I squash commits? [message #990388 is a reply to message #989787] Wed, 12 December 2012 09:30 Go to previous messageGo to next message
Stefan Lay is currently offline Stefan LayFriend
Messages: 342
Registered: July 2009
Senior Member
No, this has to be done manually by copy and paste.
Re: How do I squash commits? [message #1032251 is a reply to message #990388] Tue, 02 April 2013 19:23 Go to previous messageGo to next message
Thorsten Willard is currently offline Thorsten WillardFriend
Messages: 7
Registered: January 2013
Junior Member
Quote:
Christian Halstrick: right-click and say "Team->Reset->Soft"


When right clicking on a commit listed in history there is no "Team->Reset->Soft".
I think you meant say right click on the top most folder of the project in Package Explorer then: Team->Reset
But this says: "Select a branch to reset the current branch to"
Which is not correct.

If you right click on the commit you want to keep in the History view then hover over the "Reset" choice, 3 other sub-choices appear: Soft, Mixed and Hard.

Then you said:
Quote:
"right-click and say "Commit". This commit will contain all the changes of the last m commits together"


I assume you mean right-click on the same commit as you did when you did a "Soft reset" but there is no "Commit" choice when right-clicking on it.
Do you mean to right-click on the topmost folder in Project Explorer and go to team->Commit ?
Then you just get: "No changed items were selected, do you wish to amend the last commit?"

Re: How do I squash commits? [message #1032824 is a reply to message #1032251] Wed, 03 April 2013 13:30 Go to previous messageGo to next message
Stefan Lay is currently offline Stefan LayFriend
Messages: 342
Registered: July 2009
Senior Member
Thorsten Willard wrote on Tue, 02 April 2013 15:23
Quote:
Christian Halstrick: right-click and say "Team->Reset->Soft"


When right clicking on a commit listed in history there is no "Team->Reset->Soft".
I think you meant say right click on the top most folder of the project in Package Explorer then: Team->Reset
But this says: "Select a branch to reset the current branch to"
Which is not correct.

If you right click on the commit you want to keep in the History view then hover over the "Reset" choice, 3 other sub-choices appear: Soft, Mixed and Hard.



You should use the History View, Reset -> Soft (apparently there is no team menu), only here you can reset to an arbitrary commit.
Quote:


Then you said:
Quote:
"right-click and say "Commit". This commit will contain all the changes of the last m commits together"


I assume you mean right-click on the same commit as you did when you did a "Soft reset" but there is no "Commit" choice when right-clicking on it.
Do you mean to right-click on the topmost folder in Project Explorer and go to team->Commit ?
Then you just get: "No changed items were selected, do you wish to amend the last commit?"



After a soft reset to another commit, in 99,999% of the cases you will have changes in your working tree and you can do a normal commit, either from Team->Commit in the Package/Project Explorer (can be done on any entry, not only the topmost folder), the tool bar or the staging view
Re: How do I squash commits? [message #1032913 is a reply to message #1032824] Wed, 03 April 2013 16:00 Go to previous messageGo to next message
Thorsten Willard is currently offline Thorsten WillardFriend
Messages: 7
Registered: January 2013
Junior Member
Quote:
After a soft reset to another commit, in 99,999% of the cases you will have changes in your working tree and you can do a normal commit, either from Team->Commit in the Package/Project Explorer (can be done on any entry, not only the topmost folder), the tool bar or the staging view


But how does this squash? I don't understand. After I select the commit I want to keep and do a soft reset on it, then what? Select the next to the last commit and try to commit over it? Then Eclipse just says: "No changed items were selected. Do you wish to amend the last commit?"

You say commit from Team->commit, the tool bar or the staging view.
tool bar: I don't see a commit button on the toolbar. In which view?
staging view: I don't have anything staged. I haven't made any new commits. I just want to squash the existing ones all into the commit I did a soft rest on.
Re: How do I squash commits? [message #1033550 is a reply to message #1032913] Thu, 04 April 2013 11:04 Go to previous messageGo to next message
Stefan Lay is currently offline Stefan LayFriend
Messages: 342
Registered: July 2009
Senior Member
Quote:
But how does this squash? I don't understand. After I select the commit I want to keep and do a soft reset on it, then what? Select the next to the last commit and try to commit over it? Then Eclipse just says: "No changed items were selected. Do you wish to amend the last commit?"


The idea is the following: You have commits
c <- branch <- HEAD
|
b
|
a

You want to squash c and b.

1. Do a soft reset to a (you want to keep a)
c
|
b
|
a <- branch <- HEAD

Now you have the changes of b and c in the working tree.

2. Commit

c
|
b d <- branch <- HEAD
|/
a

Now you have created a new commit d which squashes b and c.

(Note: You could also have 1. reset to b and 2. do a commit --amend. By that you could reuse the commit message of b)

Quote:
tool bar: I don't see a commit button on the toolbar. In which view?


You can switch it on. See here: http://wiki.eclipse.org/EGit/User_Guide#Git_Workbench_Toolbar_and_Git_Workbench_Menu

Quote:
staging view: I don't have anything staged.

After reset you have a dirty working tree. In the staging view you have to stage the changes before you can commit them.

[Updated on: Thu, 04 April 2013 11:05]

Report message to a moderator

Re: How do I squash commits? [message #1034720 is a reply to message #1033550] Fri, 05 April 2013 20:25 Go to previous messageGo to next message
R Shapiro is currently offline R ShapiroFriend
Messages: 386
Registered: June 2011
Senior Member
After a soft reset the previously committed changes will still be indexed, not dirty in the working tree. That's exactly the difference between soft and mixed. So a soft reset followed immediately by a commit squashes all the intervening commits into one. Very easy (assuming you don't have unrelated changes in the working tree)

It might help to think of it as follows. The standard working pattern in Git is edit, add, commit. The three usual kinds of reset undo these to different extents. A soft reset undoes the commits, a mixed reset undoes the commits and the adds, a hard reset undoes the commits, the adds and the edits.

Note that in addition to simple squashing, a soft or mixed reset combined with the EGit index editor is a nice way to restructure a set of commits more generally. For instance you might realize that change X really belongs in commit C1 rather than commit C2, or that commit C3 should really be split into two commits. All easily done in EGit.




[Updated on: Fri, 05 April 2013 20:50]

Report message to a moderator

Re: How do I squash commits? [message #1034881 is a reply to message #1034720] Sat, 06 April 2013 02:14 Go to previous messageGo to next message
Thorsten Willard is currently offline Thorsten WillardFriend
Messages: 7
Registered: January 2013
Junior Member
Quote:
You can switch it on. See here: http://wiki.eclipse.org/EGit/User_Guide#Git_Workbench_Toolbar_and_Git_Workbench_Menu

Ok, I have the Git Workbench Toolbar switched on but when I commit I still get the same dialog as if I went to Team->commit it doesn't make any difference. It's just another way of getting to the same dialog. The dialog doesn't show me any files I can commit other than project preferences.

R Shapiro: Thank you your explanation but the issue is still HOW do I commit. Either I'm not given that option in the dialog or committing again does not squash it just adds another commit. Could someone please give numbered steps for how to do this.
Re: How do I squash commits? [message #1034884 is a reply to message #1034881] Sat, 06 April 2013 02:16 Go to previous messageGo to next message
Thorsten Willard is currently offline Thorsten WillardFriend
Messages: 7
Registered: January 2013
Junior Member
Quote:
You can switch it on. See here: http://wiki.eclipse.org/EGit/User_Guide#Git_Workbench_Toolbar_and_Git_Workbench_Menu



Ok, I have the Git Workbench Toolbar switched on but when I commit I still get the same dialog as if I went to Team->commit it doesn't make any difference. It's just another way of getting to the same dialog. The dialog doesn't show me any files I can commit other than project preferences.

R Shapiro: Thank you your explanation but the issue is still HOW do I commit. Either I'm not given that option in the dialog or committing again does not squash it just adds another commit. Could someone please give numbered steps for how to do this.
Re: How do I squash commits? [message #1035155 is a reply to message #1034884] Sat, 06 April 2013 12:00 Go to previous message
R Shapiro is currently offline R ShapiroFriend
Messages: 386
Registered: June 2011
Senior Member
Quote:
but the issue is still HOW do I commit


That's not likely to be the issue. If you don't see any staged but uncommitted changes, then for some reason the soft reset didn't happen at all. Without knowing details I can't say why, but I'm sure a successful reset to a commit other than HEAD will leave uncommitted changes in the index (ignoring weird special cases).

Maybe you should try doing the same reset operation in command-line Git to see what should have happened, for example "git reset HEAD~2".

Then run "git status" and you will see uncommitted staged changes corresponding to the last two commits.

Then do "git commit", and you will have squashed the last two commits into one. That is, the content will be the same as what you started out with but the commit sequence for the branch will be altered.



Previous Topic:Is a relative path to git repository possible?
Next Topic:Shortcut folder problem
Goto Forum:
  


Current Time: Sat Apr 20 03:21:01 GMT 2024

Powered by FUDForum. Page generated in 0.03923 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top