1

Let's say I have fileA.py and fileB.py, and I want to restore both of these file to a previous version using git checkout <commit> <filename>.

The issue I have is the versions I want to restore were committed in two different commits. Is there a way to restore both files using one command, or do I have to do each one on its own.

4
  • You must do each one on its own. (You can view both blobs with one command, using the <rev>:<path> syntax, but you'll still have to extract each one separately anyway.) Commented Jul 17, 2017 at 23:42
  • @Abdelrahman, you need different commit-hash for different file names, hence you will have to the above command for n times for n files. Commented Jul 18, 2017 at 0:37
  • @Abdelrahman, If commit-hash was same for the all files to checkout, then you should be looking for similarity between filenames so that you can target all the required files using regex in single command. Commented Jul 18, 2017 at 0:44
  • Thank you very much guys. This is what I suspected. Not a huge issue anyway Commented Jul 24, 2017 at 15:57

1 Answer 1

1

It's not possible with a single command. You can use a loop:

for x in "commit1 filea.py" "commit2 fileb.py"; do git checkout $x; done
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.