Git doesn't track changes in commits. Each commit contains a full copy of the files in the repo. "Changes" are determined by diff-ing two commits.
So, in short, there's absolutely no problem with squashing E
, B
and C
into commit F
and then merging that onto the dev branch. The B
commit will still exist on the dev branch. When git compares F
to B
, only the changes introduced by C
and E
will be attributed to F
.
You can, of course, get around this perceived problem by using git rebase
, but that comes with its own set of headaches. For example, since git rebase
changes your branch history (moving your commits on top of the latest commit from dev), if there are conflicts, you will have to re-resolve those conflicts every time you rebase. That gets old fast if your issue takes a while to resolve, requiring several rebases to keep current with dev.
Just to demonstrate that this is all true and that you have nothing to worry about, I've setup an example GitHub repo: https://github.com/cyborgx37/sandbox
To start with, we have the dev branch, which has the B
commit.
B:patch
|
A
Then I created the feature1 branch, which has commits C
, D
and E
. (Note that, because D was a merge and thus has two parents, B
also shows up in the commit history)
E
|
D:merge with dev
|\
C \
| B
A
Finally, there's the dev-with-feature1 branch.
F
|
B:patch
|
A
I created this branch off of dev, then used
git merge --squash feature1
git commit -m "F"
to squash all of feature1's commits into a single commit, F
.
If you examine the diff for the F
commit, you'll see that it doesn't "apply the patch". Since B
already contains those changes, and F
just repeats them, git doesn't associate them with F
.
From another perspective, here's the blame:
initial hello!
B:patch patch!
F new feature!!!
Git doesn't track changes in commits. It stores your complete project state. "Changes" are determined by comparing a commit to its parent (or predecessor) commit. Because B
has the patch, git associates that change with B
. So, it's expected that the patch would be in F
too. The only way it wouldn't be in F
is if you deleted the patch.