1

I noticed a discrepancy between the way EGit records the reflog for a rest action, as compared to the way Git Bash records it.

28eab8d HEAD@{0}: commit: l
959126f HEAD@{1}: 959126fc7fbf887b3bdb5bd931f50c611f48bf71: updating HEAD
f073b25 HEAD@{2}: commit: l
959126f HEAD@{3}: reset: moving to HEAD~1
b0114f6 HEAD@{4}: commit: l
959126f HEAD@{5}: 959126fc7fbf887b3bdb5bd931f50c611f48bf71: updating HEAD

HEAD@{1} and HEAD@{5} were recorded by EGIT, while HEAD{3} was recorded by Git Bash.

In addition, there seems to be a difference between the way they log branch name changes:

28eab8d9329f936c1642a591317bbe5be3fed7c1 28eab8d9329f936c1642a591317bbe5be3fed7c1 user <user@user.com> 1423771813 -0500 Branch: renamed refs/heads/test to refs/heads/testtt
28eab8d9329f936c1642a591317bbe5be3fed7c1 28eab8d9329f936c1642a591317bbe5be3fed7c1 user <user@user.com> 1423771870 -0500 Branch: renamed refs/heads/testtt to refs/heads/test
0000000000000000000000000000000000000000 28eab8d9329f936c1642a591317bbe5be3fed7c1 user <user@user.com> 1423771941 -0500 Branch: renamed test to testttt
0000000000000000000000000000000000000000 28eab8d9329f936c1642a591317bbe5be3fed7c1 user <user@user.com> 1423772021 -0500 Branch: renamed testttt to test

The first top lines are from Git Bash, and the bottom ones are from EGit. In addition, EGit makes the same change to the HEAD reflog, while Git Bash does nothing.

The biggest problem is that Git Bash does not show any lines beyond the one with the 40 0's, so I cannot see the logs when in Git Bash.

I guess that I could hack together some script that rewrites the logs, but I am wondering if there is some setting or version that I have wrong.

I am using Egit 3.4.1 and Git Bash 1.8.5.2.msysgit.0

Joseph K. Strauss
  • 4,683
  • 1
  • 23
  • 40

1 Answers1

1

The following script will fix the problems cause by EGit. Name it /bin/git-sanitize-reflog or whatever you like. In case you are nervous make a backup beforehand.

#!/bin/bash

resetFix='s/([a-f0-9]{6})[a-f0-9]{34}: updating HEAD/reset: moving to $1/'
touch tempfile
for log in $(find $(git rev-parse --git-dir)/logs/$1 -type f)
do 
    if [[ $log != "$(git rev-parse --git-dir)/HEAD" ]]
    then
        perl -pe 's/^0{40} ([a-f0-9]{40})/$1 $1/' $log | 
        perl -pe 's/Branch: renamed (?!refs\/heads\/)(.*) to (?!refs\/heads\/)(.*)/Branch: renamed refs\/heads\/$1 to refs\/heads\/$2/' |
        perl -pe "$resetFix" > tempfile

        if [[ $(cat tempfile | wc -l) -ne $(cat $log | wc -l) ]]
        then
            exit -1
        fi
    else
        HEAD_grep='^0{40}.*Branch: renamed'
        egrep -v $HEAD_grep $log |
        perl -pe "$resetFix" > tempfile
        if [[ $(wc -l tempfile) -ne $(expr $(cat $log | wc -l) - $(egrep $HEAD_grep $log | wc -l)) ]]
        then
            exit -1
        fi
    fi
    cat tempfile > $log
    echo Sanitized $log
done
rm tempfile
Joseph K. Strauss
  • 4,683
  • 1
  • 23
  • 40