Back

Explore Courses Blog Tutorials Interview Questions
+5 votes
2 views
in DevOps and Agile by (19.4k points)
edited by

I have added a file named "file1.txt" to git repo. After that I committed it, added a couple directories called dir1 and dir2, and committed them to git repo.

Now the current repo has "file1.txt", dir1 and dir2.
How can I delete "file1.txt" without affecting others like dir1 and dir2?

 

1 Answer

+5 votes
by (27.5k points)
edited by

Use git rm to remove file1.txt:

git rm file1.txt

git commit -m "remove file1.txt"

In order to remove the file only from the Git repository, not from the filesystem, use:

git rm --cached file1.txt

git commit -m "remove file1.txt"

And to push changes to the remote repository use the following command: 

git push origin branch_name 

For more commands like this please go through the following tutorial that will help you understand the git

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

29.3k questions

30.6k answers

501 comments

104k users

Browse Categories

...