How do I squash commits? [message #989644] |
Fri, 07 December 2012 02:57  |
Eclipse User |
|
|
|
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 #1032824 is a reply to message #1032251] |
Wed, 03 April 2013 09:30   |
Eclipse User |
|
|
|
Thorsten Willard wrote on Tue, 02 April 2013 15:23Quote: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 #1034720 is a reply to message #1033550] |
Fri, 05 April 2013 16:25   |
Eclipse User |
|
|
|
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 16:50] by Moderator
|
|
|
|
|
Re: How do I squash commits? [message #1035155 is a reply to message #1034884] |
Sat, 06 April 2013 08:00  |
Eclipse User |
|
|
|
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.
|
|
|
Powered by
FUDForum. Page generated in 0.07046 seconds