Delete a file with git rm
Description: Remove the file old.txt from the project and commit the change.
Hint:
git rmdeletes the file and stages the deletion.
Solution
Terminal output
$ git rm old.txt
rm 'old.txt'
$ git status -s
D old.txt
$ git commit -m "Remove old.txt"
[main 29d3f88] Remove old.txt
1 file changed, 1 deletion(-)
delete mode 100644 old.txt
$ ls
keep.txt
How it works
Din the status means the deletion is staged.- The file is still in the history, so you can bring it back from an older commit.
Read Git rm and mv.
Learn more about the similar topics:
| Tutorials |
|---|
| No Content Found. |
| Exercises & Assignments |
|---|
| No Content Found. |
| Interview Questions & Answers |
|---|
| No Content Found. |