I have a development branch with many commits. These commits include "real" changes (e.g. add a feature) as well as temporary changes (e.g. add test code in one commit, then remove it in a later commit).
The real changes from this branch are being gradually added into the master. After each addition, I rebase the develoment branch on the new master. With each cycle, difference between the development branch and the master is getting smaller. However, the rebased development branch contains all original (now rebased) commits. Some of these commits now have zero net effect.
Simple example:
DEV_BRANCH
Commit ...
Commit D: Remove all test code from f.cpp
Commit ...
Commit C: Add new feature to f.cpp
Commit ...
Commit B: Add more test code to f.cpp
Commit A: Add some test code to f.cpp
Commit ...
MASTER
Commit X: Add new feature to f.cpp
Commit ...
At this point, change to f.cpp from commit C
is already in the master as commit X
, and commits A
+B
+D
when combined have no change to f.cpp. In other words, diff between the branch and the master shows nothing for file f.cpp.
(In reality, commits A, B, C, and D may include changes to other files as well.)
Is there any way to automagically simplify commits in the development branch either during rebase or otherwise?
In the above simple example, is it possible to remove commit C
(with change already merged to master hence now "empty") and also commits A
, B
, and D
(no change when combined) automatically?
In a more complicated scenario when the commits to f.cpp modify other files as well, is it possible to remove changes to file f.cpp automatically from the commits in the development branch (to simplify them) but leave the commits present if they include changes to other files?
Rephrased, if applying all changes to a file from all commits in the development branch results in a file identical to the one in the master, is it possible to prune changes to this file from the development branch commits? (I do realize this may lead to side-effects if changes to other files need to be done in sync with those to the file that has no net effect. However, this is not a problem in my scenario because I do not need to cherry-pick any intermediate state from the development branch.)