-- Leo's gemini proxy

-- Connecting to republic.circumlunar.space:1965...

-- Connected

-- Sending request

-- Meta line: 20 text/gemini

Deleting commits from the git history


Today I wanted to fix a Git repo that contained some bad commits (i.e. git fsck complained about them). [I wanted to do this because GitLab was not allowing me to push the bad commits.]


I wanted the code to look exactly as it did before, but the history to look different, so the bad commits disappeared, and (presumably) the work done in the bad commits to look like it was done in the commits following them.


Here's what I ran:


git filter-branch -f --commit-filter '

   if [ "${GIT_COMMIT}" = "abdcef012345abcdef012345etcetcetc" ];
   then
       echo "Skipping GIT_COMMIT=${GIT_COMMIT}" >&2;
       skip_commit "$@";
   else
       git commit-tree "$@";
   fi
' --tag-name-filter cat -- --all


(Where abdcef012345abcdef012345etcetcetc was the ID of the commit I wanted to delete.)


Of course, you can make this cleverer to exclude multiple commits at a time, or run this several times, putting in the right commit ID each time.


Originally posted at 2018-02-06 13:30:58+00:00. Automatically generated from the original post : apologies for the errors introduced.


original post

-- Response ended

-- Page fetched on Mon May 27 13:25:40 2024