Reputation: 343
In a big refactoring branch, I was forced to do commits due to some git flaw (git loses track/history of moved files if too much of the content changes before committing), which left the repository with commits that are not "buildable". To be on the safe side I also pushed these commits (nowadays, just in case should I get sick). It would be great, if I could squash all that into one commit, either before or after merging main into my branch (and then back to main). This is what it looks like:
main: x --- x --- x --- x --- x
\ /
branch: x' --- a --- b --- c
How it should look like in the end:
main: x --- x --- x --- x --- x --- x
\ \ /
branch: x'--- (manySquashed) --- m
Also because the intermediate steps of the refactoring are not of interest (the whole before/after is all that's of interest), I don't need many of the pushed commits as single ones.
In many posts I couldn't find the solution to this specific request (or I just don't understand git enough - I'm a newbie with git).
EDIT: git losing history explained: What I basically have to do is extracting core functionality of a component into a base library for reuse by similar components. To not lose the history of many files (lot of edits in the past 8 years) that now go to the base library, I moved many files to the new folder. There's a naming convention applied to the files/classes that sort of marks where they belong to. As I move core functionality of lets say SpecialComponent1 to BaseComponentLib, the files/classes need an adjustment in their names. I found that after moving the files (not yet committed), when I then edit them (e.g apply the new name in the classes), git (using SmartGit) changes the "Modification" from "Renamed" to "Untracked" when the percentage of changes within the file crosses a certain amount. While I see the whole file history with "Modification" "Renamed", with "Untracked" there is none anymore. I found that I can only get around this problem when commiting the moved files before doing any edit (therefore I have the cluttered/many commits).
Upvotes: 1
Views: 145
Reputation: 51850
To squash all commits a--b--c
into one single commit, run :
git reset --soft x'
git commit
Upvotes: 2