Home > Software engineering >  Possible issue after doing `Squash and Merge`?
Possible issue after doing `Squash and Merge`?

Time:01-29

I used Squash and Merge for merging dev branch into main because I didn't want some of the commit messages from dev branch to appear in main
But now I found out that main is 1 commit ahead of dev.
And the graph shows that there is no connection between dev and main. This is something I have not seen before, and I have used Squash and merge for the first time

The graph of the repository:

git extension generated graph

Now, should I do:

  1. git checkout dev
  2. git rebase main

Else, what should I do after I did Squash and Merge to prevent unexpected problems from occurring.

Here, I cannot understand the situation. I may be thinking wrong. In that case, please tell me what is correct.

My workflow:

I have two long-lived branches main & dev. Then I have short-lived branches feature, bug, hotfix, etc. The main branch always remains production-ready. And I will delete the last feature branch when I merge dev into main

My dev branch looks like this:

dev graph

The main branch looks like this:

main graph

Note:

  • I am a newbie in git. So, my thinking can be wrong. If this is the case, please point out my mistake and tell me what is correct.
  • Any suggestion will be appreciated. Thanks in advance.

CodePudding user response:

Unfortunately, you have two conflicting desires:

I have two long-lived branches main & dev.

You didn't state it, but typically you want these long lived branches to sync up periodically, and that is what you attempted to do. But that means you can't do this:

... because I didn't want some of the commit messages from dev branch to appear in main.

By squashing you got the code to be the same in both branches, but you really need to sync up the commits as well, or else you'll have a lot of painful merges in the future. Unless you're willing to rewrite dev periodically from main, you're going to need to modify your process to make sure all commits into dev are "proper" since they will eventually end up in main also.

From now on, I would recommend merging dev into main with a regular merge (either fast-forward or with --no-ff, that's up to you). In the future, follow this rule of thumb:

It's OK to use squash-merge when merging feature branches into dev and/or main, but you should never use squash-merge when merging long lived branches together. This will prevent you from having the problem again in the future.

To fix your current situation, based on the discussion in the comments we know you are OK with rewriting both dev and main right now, and you are happy with the commits on main. Therefore I would suggest the following action to clean it up:

# rewrite the squash-merge commit message on main to be more meaningful
git switch main
git commit --amend -m "Import web app and modify profile"
git push --force-with-lease

# reset dev to look like main
git switch dev
git reset --hard main
git push --force-with lease

CodePudding user response:

After doing the steps given by new look of repo

  •  Tags:  
  • Related