Can we backtrack multiple files simultaneously?

Question

As we seen in this lesson, we can stage and commit multiple files simultaneously. Can we also backtrack on multiple files at the same time?

Answer

The answer is yes if each of the files that you would like to backtrack are in the same commit and the same branch. If this is the case, then as we see from git status, we can backtrack to the previous commit using the command

$ git checkout -- <file> ...

where the ellipses are replaced by other files which you would like to backtrack.

6 Likes

I’d just like to add that in that particular exercise you can add/backtrack/commit multiple files with this syntax:

git add scene*

which is easier than scene-1.txt scene-2.txt scene-3.txt…

:slight_smile:

6 Likes

Or you can just do this

git add .

1 Like

This actually worked for me whereas trying to add by “scene-3.txt” etc didn’t work.

In this exercise, for the part

In scene-3.txt , everywhere you see the name “LARRY” change it to “LAERTES.”
I would like to use the following code on the command-line as shown below.
Capture

However, when you display the contents of the file afterwards, the file is empty.
It works if you output to a new file then rename it to the file you want in this case, scene-3.txt
What would be a good way of accomplishing this?
Thank you for your help.

You could, for example, write the output and move operations on one line using &&:

sed 's/LARRY/LAERTES/g' scene-3.txt > tmp && mv tmp scene-3.txt

sed also provides an options to do this place:

image

It makes sense that in place is not the default behavior, too risky.