Can we backtrack multiple files simultaneously?


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?


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.


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…



Or you can just do this

git add .


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

1 Like

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.

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.

1 Like

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:


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

1 Like

Thanks bleier. This one works better for me using the wildcard* for series of filenames.

May I ask what is the tmp here?

I used tmp as the (arbitrary) name of the temporary file in which to store the sed output, before renaming that temporary file again. Does that help? :slight_smile: