git: How to Revert Some Files to a Revision?


Today, I checkout some changes in git, and created a pull request. Based on the suggestions (code review), I needed to revert some files i.e. *.Designer.cs back to their previous stats (undo the changes).

You can:

  • checkout a new branch, re-do the changes without those files, and recommit with a new pull request.
  • do it in the same branch by reverting all changes to a revision e.g. git revert revision; redo the changes and re-commit without having to raise a new pull request
  • just revert those files

With the third method, you can do the following command on windows:

1
2
3
4
@for /f "usebackq delims==" %f in 
  (`find . -type f -name "*.Designer.cs" -print`) do (
  git checkout revision %f
)
@for /f "usebackq delims==" %f in 
  (`find . -type f -name "*.Designer.cs" -print`) do (
  git checkout revision %f
)

On Linux, you can do similarly:

1
2
3
4
@for f in $(find . -type f -name "*.Designer.cs" -print) 
do 
    git checkout revision $f
done
@for f in $(find . -type f -name "*.Designer.cs" -print) 
do 
    git checkout revision $f
done

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
210 words
Last Post: C/C++ Coding Exercise - Nim Game
Next Post: The True Exception Handlers in PHP and Javascript

The Permanent URL is: git: How to Revert Some Files to a Revision?

One Response

  1. geeksonrepair

Leave a Reply