Reputation: 1888
As mentioned in the title, I want to perform git revert on a commit that made some undesirable changes but only in a certain folder/directory.
Upvotes: 2
Views: 116
Reputation: 35075
What about:
git revert --no-commit
Edit: For git >=2.23
please see VonC's answer.
Upvotes: 2
Reputation: 1327164
With Git 2.23 (August 2019) and the new command git restore
, plus the : pathspec signature:
git restore -s@~ -SW -- :path/to/folder/**
Long form:
git restore --source @~ --staged --worktree -- :path/to/folder/**
Check the result with git status
, then commit.
The OP adds:
I will need to do a
git reset
of the files I do not want to keep changes of, before doinggit checkout
on them.
Doing onlygit checkout
does not work because aftergit revert
, the modified files are in the staging directory.
Yes, that is why git checkout
is confusing, and is in the process of being replaced by:
git switch
(for branches only)git restore
(for files only)No need for revert+reset+checkout: if you want to restore files... use git restore
.
Upvotes: 3