getting help from the past in git
-or how to view old branch history after doing a git rebase-
problem:
sometimes I rebase a feature branch onto development branch and some changes get altered in the midst of resolving conflicts by hand.
after the rebase gets finished I want to take a look at how these changes looked like before the rebase.
solutions:
a naive solution is to take a copy of the whole repo before the rebase -safety through primitiveness-
another is to create a temporary branch that points to the same feature branch before the rebase
can be done like
sh git checkout myfeature git branch myfeature-pre-rebase git rebase develop
this is possible since git-rebase just copies a sequence of commits from a place to another and then points the target branch -myfeature in our case- to the top most commit in the copied commits, so you'd only need a new pointer that points to the old copy and stays un-altered -myfeature-pre-rebase-.
this one helps when I have already done the rebase and forgot to add the backup branch and haven't yet cleaned up dangling commits:
when the rebase is finished the old copy of myfeature commits still exists but is 'dangling', this means they dont have any branches that point to them, any of their ancestors or any of their descendants, hence to some degree inaccessible -imagine how they feel-
this is when this command can help
sh git fsck --dangling | while read line; do echo $line | awk '{print $3}' | xargs git log -1; done;
git fsck --dangling
lists dangling commits in formatcommit dangling <hash>
-this can take a while-after that the third column of each line is passed to
git log -1 <hash>
using xargs for displaying commit infonow I have to find the commit with the same message as the latest commit in the 'myfeature' branch
then I create a new branch that points to that commit with `git branch myfeature-pre-rebase
that's it
if you think I'm missing something, please let me know in the comments