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

  • Home
  • SEARCH
  • 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 1106147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:44:49+00:00 2026-05-17T01:44:49+00:00

I am writing a script that requires checking whether a particular commit is a

  • 0

I am writing a script that requires checking whether a particular commit is a Merge/Revert commit or not, and I am wondering if there is a git trick for that.

What I came up with so far (and I definitely don’t want to depend on the commit message here) is to check HASH^2 and see if I don’t get an error, is there a better way?

  • 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-05-17T01:44:49+00:00Added an answer on May 17, 2026 at 1:44 am

    Figuring out if something is a merge is easy. That’s all commits with more than one parent. To check for that, you can do, for example

    $ git cat-file -p $commit_id
    

    If there’s more than one `parent’ line in the output, you found a merge.

    For reverts it’s not as easy. Generally reverts are just normal commits that happen to apply the diff of a previous commit in reverse, effectively removing the changes that commit introduced. They’re not special otherwise.

    If a revert was created with git revert $commit, then git usually generates a commit message indication the revert and what commit it reverted. However, it’s quite possible to do reverts in other ways, or to just change the commit message of a commit generated by git revert.

    Looking for those generated revert commit message might already be a good enough heuristic for what you’re trying to achieve. If not, you’d have to actually look through other commits, comparing their diffs against each other, checking if one is the exact reverse operation of another. But even that isn’t a good solution. Often enough reverts are slightly different than just the reverse of the commit they’re reverting, for example to accommodate for code changes that happened between the commit and the revert.

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

Sidebar

Related Questions

I am writing a script that checks if given domain is parked or not.
I am writing a script that requires users to choose which parts of the
We are writing a SaaS like solution that requires our customers to SCRIPT SRC
I am writing a script that will do some automated things, and it requires
I am writing a marquee script because I do not like the fact that
I'm writing a script that (when the enter button is pressed) requires some user
I'm writing a script that will constantly scan iTunes for new dialog boxes and
I'm writing a script that asks the user for several options and then, via
I am writing a script that will look in a custom reports directory, copy
I'm writing a script that will ping my ip range. Here's what I have

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.