Version 5 (modified by 11 years ago) ( diff ) | ,
---|
Cleaning your local history
Assuming the case you push end-of-day dummy-message commits to a backup bare remote for your development, so that you have a long history. (And that public tracked branches are left clean for git-pulls and local comparisons).
When applying patches out of your local commits, it seems it can happen that the checksums on the (public) feature branch could get different (maybe due to whitespace problems, or so).
In order to have a clean history, with identical SHA-1 hashes and hence common ancestors actually recognized, you could clean it up by moving the unpatched commits on top of the feature branch.
This means for instance, if you are working on a feature_X_local branch for development work on the public feature_X feature branch:
o-------o-------o-------o-------o-------o master [public] \ o------o----A'-----B'-----C' feature_X [public] \ | | | \ /-pA /-pB /-pC A------B------C-----D----E feature_X_local [local]
pA
, pB
and pC
are patches you sent through the Patch Manager, and it happened you had different checksums between your local and public commits (A!=A'
, B!=B'
, C!=C'
).
NOTE: Despite of this, always check that a patch can apply (git apply --check
) before submitting them.
If you want to clean your local history at some point, you need to bring D
(and E
) on top of C'
, the HEAD
of feature_X:
$ git stash $ # branch situation $ git branch feature_X master * feature_X_local $ # create a temporary branch ``_tmp'' which HEADs to the last /patched/ commit (`C`) $ git checkout -b _tmp feature_X_local $ git reset --hard C $ # ..see "C" node in the graph above $ # move commits /from/ the common ancestor (ie C) between ``_tmp'' and ``feature_X_local'' (ie {D,E}) on top of ``feature_X'' $ git rebase --onto feature_X _tmp feature_X_local $ # cleaning $ git branch -D _tmp
Done:
o-------o-------o-------o-------o-------o master \ o------o----A'-----B'-----C' feature_X \ D----E feature_X_local
It can also happen that some unpatched commits are in between other patched commits (some hotfix?): in this case you can just rewrite your local history by moving all patched commits before the unpatched ones beforehand (git rebase -i HEAD~N ...
, see Git4rasdaman).