3

I have a branch called work_in_progress which is used to debug and test code with many small commits. All of them have redundant commit messages. When I'm finished I want to merge squash to master branch. Usually this is one single command when merging using the --squash parameter.

But how do I do it with SmartGIT?

The documentation here How to perform squash merges seems to be wrong because there is no option "Branch consisting of selected commit and its ancestors".

The documentation here How to perform normal merges and squash merges simply does not work. I have tried it and I still see all the small commits in the log. I can delete the work_in_progress branch afterwards, all fine, but I want a single commit with a single commit message in the history of the master branch.


Edit: Here is a screenshot from my commit dialog. I guess I'm missing the "Simple commit" option?! Maybe I don't understand the instructions^^ enter image description here


Edit 2: Here is a screenshot of the Log. The second commit from the top was done using SmartGIT. You can see that all the intermediate commits (including the messages) are visible in the history. The branch was called XYZ_work_in_progress. The last (top most) commit was done using "git merge --squash ABC_work_in_progress" but all the commits are swallowed so it's a clean history. All the work from the branch is accumulated into a single commit with a single message :-) enter image description here

FrozenTarzan
  • 834
  • 10
  • 30
  • When following "How to perform normal merges and squash commits", it would be helpful to see a screenshot of your Log after running through this procedure. – mstrap Oct 22 '15 at 18:14
  • You talk about the SmartGIT log? I think I would have to test it again with some dummy commits or is it possible to view the log from the past? I took a look at the commands that are sent by SmartGIT and there is no --squash (as far as I remember). The GIT log itself just shows two branches. One of them has, e.g., 3 commits. They are then merged back to the master branch as another commit. This is fine, but the master still shows all 3 commits in addition to the "merge" commit. – FrozenTarzan Oct 23 '15 at 07:17
  • It's hard to understand without a concrete example. Please to set up a small test repository for which the wrong behavior is reproducible and post screenshots for this one. For me squash merging works as expected. – mstrap Oct 23 '15 at 11:47
  • @mstrap: I actually want exactly the same behavior as "git checkout master" then "git merge --squash work_in_progress" then "git commit -m "a single comment for all work that has been done in this branch"". Related stackoverflow thread: [link](http://stackoverflow.com/questions/3697178/git-merge-all-changes-from-another-branch-as-a-single-commit). Do I still need to setup an example? If I have the time I will try it, but I think the purpose should be clear. Have you tried it by yourself? Does the newly created commit only contain a single message/entry in the history of the master branch? – FrozenTarzan Oct 27 '15 at 15:17
  • I have tried it and when selecting to squash on commit, output is as expected (one simple commit, no merge commit). – mstrap Oct 27 '15 at 15:49
  • How do you "select to squash". The instructions (linked in my question) don't mention it. And as I said the option "Branch consisting of selected commit and its ancestors" does not exist. Have you been following exactly these instructions: [here](http://www.syntevo.com/doc/display/SG/How+to+perform+normal+merges+and+squash+merges). I have done it through the "main window" not the "log window". It is also counterintuitive how the commits are selected in the merge step. In the end the article says "Simple commit" to perform a squash commit, this does not exitst in my version 7.0.3. – FrozenTarzan Oct 28 '15 at 06:45
  • "Simple Commit" option is exactly what is necessary and what is present for me. This is the reason why I was asking for screenshots. – mstrap Oct 28 '15 at 12:35
  • I have added a screenshot to my question :-) – FrozenTarzan Oct 28 '15 at 12:41
  • What about the Log for the repository root -- can you see "Merging" state there? – mstrap Oct 28 '15 at 16:51
  • When merging, did you select to merge to working tree, not to create a merge commit? If so, it would be interesting to see Log screenshot immediately after invoking the Merge. – mstrap Oct 29 '15 at 20:12
  • Yes I selected "merge to working tree". Hmm the log should look the same? It's just that the current changes are not commited? So only the "Merge remote-tracking branch 'origin/FOO_work_in_progress'..." is not present in the log. You asked about the Simple commit, so does your GUI look different? What version of SmartGIT do you use? I use it with Ubuntu, maybe you have an other OS too? – FrozenTarzan Oct 30 '15 at 07:59
  • I'm on Windows 7, but that shouldn't matter. Immediately after invoking Merge, the Log must not yet display the merge commit, but it should denote "Merging" state by a virtual node. Is this the case? Does the Repositories view in the main window also denote "Merging" state and blue exclamation mark? It should. – mstrap Oct 30 '15 at 09:28
  • @FrozenTarzan: Is it a desired or an undesired effect for you, that the red line from the tip of the feature branch (line 3) connects to the merge (line 2) in the `Edit 2` image ? — I am asking, because with my squash commit (I did get the option), this line is missing... – Frank N Feb 04 '16 at 12:46
  • @Frank N: No this is not desired. I want multiple commits to be merged to a single new commit with a new commit message also. As you can see in the Edit 2 image the first commit message is such a commit but it was created using the "git --squash" so no one can see all the intermediate commits. – FrozenTarzan Feb 05 '16 at 07:13

2 Answers2

7

Here's the typical situation: Things developed on your feature branch, meanwhile the world kept turning and more stuff happened on the common master branch.

before: rebase feature branch (recommended)

  1. feature and master branch, all pulled and pushed. No pending commits.
  2. You should have checked out your feature branch and be on its tip (head-revision), the yellow-green label tells you. (Having yellow and green next to each other assures you that there is no push or pull pending.)

enter image description here

4) right-click on the master tip (line1) pick Rebase HEAD to... (certainly not Rebase to HEAD... ➝ trouble, that won't become so obvious for several steps...). Press the Button in the dialog to confirm.

5) You got the feature commits played on top. As hollow orange circles, since things are not yet committed.

6) right-click on feature branch, say Push to.... Pick (o)Tracked or matching branch and —important— [x]Force Pushing (since you are “changing history” of your feature branch...)

History is now looking clean, your commits being in line, aka fast-forwardable:

enter image description here

Squash commit

  1. Switch to (check out) Master tree. Right-click on feature branch, say Merge.... In the options dialog, you have to pick Merge to Working Tree (otherwise the commit happens without you being able to pick any options, i.e. squash).

enter image description here

  1. you may or may not have to go through resolving and then continue.

  2. Finally, say commit. Pick (o) Simple commit (one parent, "squash")

enter image description here

...and there she is:

enter image description here

Frank N
  • 9,625
  • 4
  • 80
  • 110
  • Hi Frank, thanks a lot for all the screenshots and detailed descriptions! Unfortunately the resulting log looks exactly the same compared to my last edit in my question. All the commits of the feature are still present in the history (red paths) which is not the same as a squash commit using only git commands. Developers can still read the commit messages of all the "intermediate" commits which I don't want them to. I want only a single commit, a single commit message. Maybe the answer is just to use git console for squash merges... – FrozenTarzan Feb 08 '16 at 12:38
  • Well, they are _visible_, but they are not on the ’main path’. So most colleagues won't see them, unless they turn on your feature branch in Log View➝Branches View➝origin➝.... (If you care about simplictiy.) – Frank N Feb 08 '16 at 14:05
  • If you care about _privacy_, you better don't create a remote (tracking) branch of your feature in the first place... Note, that you can also squash-push several committed but unpushed changes in the outgoing panel of the main smartgit view. (Do a few and right-click on 'em) – Frank N Feb 08 '16 at 14:09
  • 1
    I see your point, but the answer to my question seems to be "this is not possible with SmartGit". This is fine for me, I just wanted to be sure. Regarding "privacy" it is more like our web-interface to our git server lists all of them in the same hierarchy so there is basically no way to distinguish between "intermediate commits" and a merge commit. Its just about visualization of changes. Thank you for your time and answers! – FrozenTarzan Feb 08 '16 at 15:07
1

Newer versions of SmartGit provide a simple solution. You can select several commits and simply choose "Squash Commits..." from the popup menu:

Popup menu with the squash option

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574