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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T20:21:42+00:00 2026-05-21T20:21:42+00:00

I’m trying to use git checkout <hash> <directory> to checkout a previous revision of

  • 0

I’m trying to use git checkout <hash> <directory> to checkout a previous revision of a directory in my repo. This works to restore the files in the directory to their previous state, the only problem is that subdirectories that were added since the revision I checked out don’t disappear.

For example, if my directory structure were the following:

HEAD:
thing/dir1/
thing/dir2/

HEAD^:
thing/dir1/

If I do git checkout <hash>, then I go into detached HEAD mode and everything matches fine. If instead I do git checkout <hash> thing/, the contents of thing/dir1/ will revert, but thing/dir2/ will stay put.

Running git status shows the file modifications from thing/dir1/, but doesn’t mention thing/dir2/. This is weird, because in the context of HEAD^, thing/dir2/ shouldn’t exist and should therefore be gone. git clean doesn’t help because it doesn’t even show up as untracked.

Is there a way to checkout a previous revision of a directory which perfectly matches, without having to checkout the entire working tree?

UPDATE:

Looks like this will work:

git reset <hash> thing/
git checkout <hash> thing/
git clean -fd thing/

This leaves my working tree and index in a strange state, but has the desired effect.

  • 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-21T20:21:43+00:00Added an answer on May 21, 2026 at 8:21 pm

    From http://git-scm.com/docs/git-checkout:

    Updates files in the working tree to
    match the version in the index or the
    specified tree
    . If no paths are given,
    git checkout will also update HEAD to
    set the specified branch as the
    current branch.

    Further below it also says:

    When < paths > or –patch are given, git
    checkout does not switch branches. It
    updates the named paths in the working
    tree from the index file or from a
    named (most often a
    commit). In this case, the -b and
    –track options are meaningless and giving either of them results in an
    error. The argument can be
    used to specify a specific tree-ish
    (i.e. commit, tag or tree) to update
    the index for the given paths before
    updating the working tree.

    In other words, since you are not switching branches, the working directory will not reflect any changes to the HEAD pointer, but will show files that belong to the tree-ish, in this case it’s HEAD^

    The reason why thing/dir2 is still left on disc is that it still belongs to current HEAD (remember, HEAD is not moved) and there is no information in the tree-ish whats missing from the three-ish (in this case thing/dir2). So in effect you have thing/dir1 checked out to reflect the state of the HEAD^ hash and also thing/dir2 on disc since it belongs to HEAD.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I am trying to render a haml file in a javascript response like so:
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.