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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:54:50+00:00 2026-05-14T14:54:50+00:00

Is there a way to go through different commits on a file. Say I

  • 0

Is there a way to go through different commits on a file.
Say I modified a file 5 times and I want to go back to change 2, after I already committed and pushed to a repository.

In my understanding the only way is to keep many branches, have I got that right?
If I’m right I’m gonna have hundreds of branches in a few days, so I’m probably not understanding it really.

Could anyone clear that up please?

  • 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-14T14:54:50+00:00Added an answer on May 14, 2026 at 2:54 pm

    Let’s start with a qualitative description of what we want to do (much of this is said in Ben Straub’s answer). We’ve made some number of commits, five of which changed a given file, and we want to revert the file to one of the previous versions. First of all, git doesn’t keep version numbers for individual files. It just tracks content – a commit is essentially a snapshot of the work tree, along with some metadata (e.g. commit message). So, we have to know which commit has the version of the file we want. Once we know that, we’ll need to make a new commit reverting the file to that state. (We can’t just muck around with history, because we’ve already pushed this content, and editing history messes with everyone else.)

    So let’s start with finding the right commit. You can see the commits which have made modifications to given file(s) very easily:

    git log path/to/file
    

    If your commit messages aren’t good enough, and you need to see what was done to the file in each commit, use the -p/--patch option:

    git log -p path/to/file
    

    Or, if you prefer the graphical view of gitk

    gitk path/to/file
    

    You can also do this once you’ve started gitk through the view menu; one of the options for a view is a list of paths to include.

    Either way, you’ll be able to find the SHA1 (hash) of the commit with the version of the file you want. Now, all you have to do is this:

    # get the version of the file from the given commit
    git checkout <commit> path/to/file
    # and commit this modification
    git commit
    

    (The checkout command first reads the file into the index, then copies it into the work tree, so there’s no need to use git add to add it to the index in preparation for committing.)

    If your file may not have a simple history (e.g. renames and copies), see VonC’s excellent comment. git can be directed to search more carefully for such things, at the expense of speed. If you’re confident the history’s simple, you needn’t bother.

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

Sidebar

Related Questions

Is there a way through the Revit API to change which document is the
Is there a way through the .Net aframework (or has someone written something similar)
If I have 3 radio buttons, is there a way through jQuery of finding
I was wondering if there was any way through C# or C++ to send
Is there a way to iterate through every node in a neo4j database using
Is there a way of iterating through an array but performing an operation on
Is there a way to look through the cache for all objects in the
Is there a way to itterate through all of the terms held against a
Is there a way to click through element, even if it's on top of
Is there a way to search through an associative array with an unknown number

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.