Assuming the hash of the commit you want is c5f567
:
git checkout c5f567 -- file1/to/restore file2/to/restore
The git checkout man page gives more information.
If you want to revert to the commit before c5f567
, append ~1
(where 1 is the number of commits you want to go back, it can be anything):
git checkout c5f567~1 -- file1/to/restore file2/to/restore
As a side note, I’ve always been uncomfortable with this command because it’s used for both ordinary things (changing between branches) and unusual, destructive things (discarding changes in the working directory).
There is also a new git restore
command that is specifically designed for restoring working copy files that have been modified. If your git is new enough you can use this command, but the documentation comes with a warning:
THIS COMMAND IS EXPERIMENTAL. THE BEHAVIOR MAY CHANGE.
Related Posts:
- How can I switch to another branch in git?
- How do I check out a remote Git branch?
- How do I delete a Git branch locally and remotely?
- What is git tag, How to create tags & How to checkout git remote tag(s)
- How do I delete a Git branch locally and remotely?
- How do I rename a local Git branch?
- How do I undo the most recent local commits in Git?
- How do I revert a Git repository to a previous commit?
- Download single files from GitHub
- How to get just one file from another branch?
- How do I revert a Git repository to a previous commit?
- How do I revert all local changes in Git managed project to previous state?
- How do I revert all local changes in Git managed project to previous state?
- What does “Git push non-fast-forward updates were rejected” mean?
- Else clause on Python while statement
- What’s the difference between git switch and git checkout
- git checkout tag, git pull fails in branch
- Git: How to update/checkout a single file from remote origin master?
- Set up git to pull and push all branches
- Invalid VCS root mapping – 3 errors on my project
- Updates were rejected because the remote contains work that you do not have locally
- how to reset develop branch to master
- git checkout master error: the following untracked working tree files would be overwritten by checkout
- How can I see the changes in a Git commit?
- How can I delete all Git branches which have been merged?
- Git checkout – switching back to HEAD
- git checkout all the files
- Pull latest stable release via git [closed]
- Version control with a team of non-developers
- Painless way to track remote Git repo for WordPress updates
- Questions about Git and WordPress [duplicate]
- What does ‘–set-upstream’ do?
- What does ‘–set-upstream’ do?
- How to use Git Revert
- How do I properly force a Git push?
- How do I rename a local Git branch?
- How to remove local (untracked) files from the current Git working tree
- Git merge hotfix branch into feature branch
- Git submodule update
- How do I discard unstaged changes in Git?
- How to modify existing, unpushed commit messages?
- Git pushing to remote branch
- How to revert a merge commit that’s already pushed to remote branch?
- GitHub Error Message – Permission denied (publickey)
- How do I push a new local branch to a remote Git repository and track it too?
- How do you push a tag to a remote repository using Git?
- Gitignore not working
- How to solve SSL certificate: self signed certificate when cloning repo from github?
- How do I resolve git saying “Commit your changes or stash them before you can merge”?
- How to revert multiple git commits?
- How do I rename both a Git local and remote branch name?
- How do I fix a Git detached head?
- How to cherry-pick multiple commits
- Undo git pull, how to bring repos to old state
- Another git process seems to be running in this repository
- rejected master -> master (non-fast-forward)
- merge one local branch into another local branch
- Git error on commit after merge – fatal: cannot do a partial commit during a merge
- Can I share my private GitHub repository by link?
- Is there a “theirs” version of “git merge -s ours”?
- Download a single folder or directory from a GitHub repo
- Is there a “git touch” so I can push the same file with a new timestamp?
- Branch from a previous commit using Git
- Hard reset of a single file
- Hard reset of a single file
- How to remove remote origin from a Git repository
- Not a valid object name: ‘master’
- .gitignore and “The following untracked working tree files would be overwritten by checkout”
- git add remote branch
- Undo a git stash
- Undo git stash pop that results in merge conflict
- How can I undo git reset –hard HEAD~1?
- Unity Collaborate vs GitHub
- SourceTree keeps asking for Github password
- Git’s local repository and remote repository — confusing concepts
- How to change the license for a project at Github?
- Git add all files modified, deleted, and untracked?
- How to switch back to ‘master’ with git?
- Github Authentication Failed – … GitHub does not provide shell access
- How do I pull files from remote without overwriting local files?
- How can I see which Git branches are tracking which remote / upstream branch?
- How to keep a branch synchronized/updated with master?
- What is the Git equivalent for revision number?
- Your repository has no remotes configured to push to
- Specify an SSH key for git push for a given domain
- How do I “un-revert” a reverted Git commit?
- How to create a local branch from an existing remote branch?
- git push not send changes to remote git repository
- How to merge a specific commit in Git
- How to use Git and Dropbox together?
- Git: Where exactly is the “working directory”?
- What exactly does the “u” do? “git push -u origin master” vs “git push origin master”
- WordPress Health Tool reporting version control as a critical issue
- What is the usual process of saving changes made at the CMS level into source control?
- Add latest commit info on login footer using login_footer hook
- How should I be handling my theme version numbering?
- WordPress Core files not being ignored by Git
- Display GitLab repositories of the logged in user on a page
- version control for wordpress? (wordpress folder and database at same time)
- How to retrieve the last modification date of all files in a Git repository