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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:51:10+00:00 2026-05-16T16:51:10+00:00

In git, I can specify the previous revision by saying HEAD^ or HEAD~1 .

  • 0

In git, I can specify the previous revision by saying HEAD^ or HEAD~1. What about going the other way? Suppose I’m on revision X, and I do git checkout X^. How do I go back?

Something like git checkout X+?

  • 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-16T16:51:11+00:00Added an answer on May 16, 2026 at 4:51 pm

    You can’t really do precisely that. History in git is a directed acyclic graph – each commit contains references to its parents, but parents don’t have references to their children.

    The problem here should become obvious when you think about a commit you created multiple branches from. Which “next commit” do you mean? With parents, you can number off (a normal merge commit has a first and second parent), but how do you do that with children? Even if you know what branch you’re trying to be on (e.g. you’ve checked out master~4 and now you want to look at master~3) it’s not well-defined – you could be in a situation like this:

    - X (HEAD) - o - o - o - Y (master)
       \                    /
        o - o - o ----------
    

    That said, in simple cases, you could do something like this:

    git checkout $(git rev-list HEAD..master | tail -n 1)
    

    Clearly that’ll work fine with linear history. With merges… rev-list works from present to past in the history, following it backward. I believe it follows the first parent first, so the thing printed last will be the commit after HEAD found by following all last parents.

    Edit: That does assume that you know which branch you want to move forward toward. If you don’t… well, you’re pretty much stuck looking on all refs for commits which have the current HEAD as parent – probably grepping the output of git rev-parse:

    git rev-list --all --children | grep ^$(git rev-parse HEAD)
    

    Then grab the other SHA1 from the line (use awk, whatever). You’ll have to manually inspect or make an arbitrary choice if there are multiple results though…

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

Sidebar

Related Questions

How can I ignore directories or folders in Git using msysgit on Windows?
How can I remove those annoying Mac OS X .DS_Store files from a Git
Git has a much-touted(?) octopus-merge capability that can merge many heads into one. But
Browsing through the git documentation, I can't see anything analogous to SVN's commit hooks
I know I can do most of this by hacking Trac and using Git
I have a git repository with multiple branches. How can I know which branches
Say I have a git repository and I've been working on master, can I
running git instaweb in my repository opens a page that says 403 Forbidden -
Our git server will be local, but we want an server where our local
In Git, how could I search for a file or directory by path across

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.