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 9066087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:39:41+00:00 2026-06-16T16:39:41+00:00

I frequently use fixup!, squash! and rebase -i to clean up, correct, or just

  • 0

I frequently use “fixup!”, “squash!” and “rebase -i” to clean up, correct, or just fiddle with recent, unpushed history. I’d like to find a way to get Git to automatically choose which commit makes the most sense for interactive rebasing, so that I could define an alias to do a quick interactive rebase.

I think the best commit in such cases would be the most recent ancestor to either:

  • appear in any other branch (local or remote)
  • have more than one parent
  • have no parents

The first condition ensures that I don’t rewrite commits that might affect others. The second ensures that I don’t try to rebase “through” a merge, which is definitely not what I want. The third is just a sanity check.

So the question is, how do I use Git find that commit?

  • 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-16T16:39:42+00:00Added an answer on June 16, 2026 at 4:39 pm

    So it’s not pretty, but this is what I’ve come up with.

    #! /bin/sh
    
    commit=$(git rev-parse HEAD)
    
    while [ "$(git log --format="%p" -1 $commit | wc -w)" -eq 1 ] \
          && [ "$(git branch --all --contains $commit | wc -l)" -eq 1 ]
    do
        commit=$(git rev-parse "$commit^")
    done
    
    echo $commit
    

    I’m sure there’s a simpler, more robust way of accomplishing this, but it seems to do what I want. Suggestions and improvements are very much welcome. (It’d be nice to do this with just Git plumbing instead of relying on wc, for example.)

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

Sidebar

Related Questions

I use VSTO Excel template based solutions frequently. One of the things I like
I frequently find myself creating classes which use this form (A): abstract class Animal
I frequently use Moose to make sure my data have suitable default values, like
In SQL Server I frequently use FOR XML AUTO, which allows something like SELECT
I frequently use constants defined like: private static final int myConstant_x = 1; private
I frequently use the Reply with History without Attachment(s) and Reply to All with
People use frequently something like: <ListBox ItemsSource={Binding ElementName=thisControl, Path=ListIndexes}> <ListBox.ItemTemplate> <DataTemplate> <StackPanel> <Label Content={Binding
I frequently use sorted and groupby to find duplicates items in an iterable. Now
I frequently use a generator that returns a certain class. What I'd like to
I very frequently use logic something like this when writing to normalised databases. In

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.