Squash fixes directly to function without reinstalling or merging

I've read a bit about --squash

ing commits, but they all seem to go hand in hand with --rebase

.

I have a branch with a set of commits like this:

(Feature)          A --> B --> C --> D --> E --> F --> G
                  /
(Master)  M1 --> M2 --> M3

      

Let's say I want to merge with a branch Master

, but first I want to clear commits from my function.

Is it possible:

  • Select commit B, E and F and squash them together as one commit?

OR

  • Can I only squash the commits that come in order so squash: (A, B and C) or squash (D, E and F), etc.?

Anyway, can I do the squash directly on my function, WITHOUT without unnecessary initialization with Merge

or Rebase

?

If so, how can I do this using Git?

+3


source to share


2 answers


Yes and no.

Yes, you can avoid changing the parent commit 'A', but I believe you cannot avoid git rebase

. You can do an interactive redirect with the same root:



git rebase -i M2 Feature

      

Then you can do whatever you want and at the end of the branch Feature

will still start with commit M2.

0


source


In my team workflow, we often merge into an upstream in the middle of a bunch of commits, and reloading can get ugly. I found this useful for squash all commits that are ahead of the master into one:



# Commit any working changes on branch "mybranchname", then...
git checkout master
git checkout -b mybranchname_temp
git merge --squash mybranchname
git commit -am "Message describing all squashed commits"
git branch -m mybranchname mybranchname_unsquashed
git branch -m mybranchname

# Optional cleanup:
git branch -D mybranchname_unsquashed

# If squashing already-pushed commits...
git push -f

      

0


source







All Articles