Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8114891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:17:30+00:00 2026-06-06T03:17:30+00:00

I was doing a refactoring, and just kept amending every time I made any

  • 0

I was doing a refactoring, and just kept amending every time I made any decent progress. It has gone very well, and I realized it would be nice to be able to show people how I handled such a huge refactoring (lots of tiny steps, just nudging code around, with a green test suite at every point).

The commits are all in my reflog. Is there a way to turn each of those amended commits into its own real commit (sorry, don’t know the terminology) so that users can see each step rather than just the aggregated ones on lines 81 and 57? I don’t need unique messages for the commits or anything, just that they are captured in the history.

This is all still in my local repo.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T03:17:31+00:00Added an answer on June 6, 2026 at 3:17 am

    Reconstructing the reflog might not be as difficult as it first appears. You can regenerate the reflog’s commits into distinct branches, or you can use git read-tree to generate a single newbranch containing a portion of the reflog.

    One commit per branch solution:

    Suppose you wanted distinct branches for each commit. First, copy your repository. You’re going to change your reflog in this process, so you might as well use a throwaway version. Second, examine your reflog and find the commit with which you want to start. It’s going to look like HEAD@{n}. Suppose it were HEAD@{49}. Then, try this script, replacing the head -50 with head -<n + 1>, whatever that is in your case:

    #!/bin/sh
    reflog=$(git reflog | head -50 | awk '{ print $1 }')
    i=0
    for ref in $reflog; do
        git checkout -B "reflog_$i" $ref
        i=$(expr $i + 1)
    done
    

    This is grabbing your reflog’s commit history once, then iterating over it, generating reflog_$i branches along the way. You can cherry-pick, merge, or manipulate them however you want. If this is simply for a presentation, you could write a short script that executes git checkout on the branches, runs the test suite, and shows greens the whole way. Remember, reflog_1 represents the most current history; reflog_<n+1> the oldest.

    #!/bin/sh
    for i in $(seq 50 1); do
        git checkout "reflog_$i"
        ./test-suite.sh
    done
    

    Throw it up on a projector while you explain your commit method and it’d be a nice backdrop.

    If you want to combine all the branches, you can run this ruby script to apply them in order (or create an equivalent in whatever language you’re comfortable with). Let me reiterate that you should have your directory backed up, because this is rather destructive.

    #!/usr/bin/env ruby
    n = 50
    
    n.downto 0 do |i|
      system "
        git read-tree reflog_#{i}
        git commit -m 'Refactoring #{n - i}'
        git checkout -- .
        git br -D refog_#{i}
      "
    end
    

    Putting all commits on the same branch using git read-tree

    First, copy your repository. Then use a script like the one below. Per the discussion in the first solution, change the two <n + 1> to whatever depth you want in your reflog, plus one. Note the additional pipe to sed. You must use it or something like it, lest the reflog apply to newbranch in reverse chronological order. There’s surely a way to do this without using both awk and sed, but this works:

    #!/bin/sh
    reflog=$(git reflog | head -<n + 1> | awk '{ print $1 }' | sed -n '1!G;h;$p')
    git checkout -B newbranch HEAD@{<n + 1>}
    for ref in $reflog; do
        git read-tree "$ref"
        git commit --no-verify -m "Adding commit $ref"
        git checkout -- .
    done
    

    The final result will be newbranch, which should contain all the commits between HEAD@{0} and HEAD@{n}, based upon commit HEAD@{n+1}.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am doing some significant refactoring and feature-adding on a project, and have just
While doing some refactoring I've found that I'm quite often using a pair or
What is the best way of doing version control of large scale refactoring? My
Doing some refactoring in some legacy code I've found in a project. This is
I am doing a refactoring on code is translated from other languages into Java
I am doing some refactoring on a piece of code to transform all blocking
I was doing some refactoring and wanted to break into the debugger and return
I stumbled across this when doing a refactoring with Grails 2.0.1 but I pulled
I am currently refactoring a very useful but poorly designed class in C++, and
I've been tasked with doing refactoring to a Java Swing application we have here

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.