How do i remove a file in a git repository?
-
git rm page: http://bit.ly/2oUUXEW
Here is a test git repository, with these file in it.
$ ls lastorders.php NewUser.txt README.md Test.php
To remove the file from the git repository
$ git rm lastorders.php rm 'lastorders.php'
Check the status.
$ git status On branch master Your branch is ahead of 'origin/master' by 1 commit. (use "git push" to publish your local commits) Changes to be committed: (use "git reset HEAD <file>..." to unstage) deleted: lastorders.php ```bash **Commit the change.** $ git commit -m "removed lastorders.php file" [master e8fc60e] removed lastorders.php file 1 file changed, 1 deletion(-) delete mode 100644 lastorders.php
Check the status.
$ git status On branch master Your branch is ahead of 'origin/master' by 1 commits. (use "git push" to publish your local commits) nothing to commit, working directory clean
If you want to remove only the file from the git repository but not the filesystem, use this command, git with the cached option, see git rm man page
$ git rm --cached lastorders.php rm 'lastorders.php' $ ls lastorders.php NewUser.txt README.md Test.php
Check status show a file deleted from git repository & an untracked file, because git goes not know about it after the remove command.
$ git status On branch master Your branch is up-to-date with 'origin/master'. Changes to be committed: (use "git reset HEAD <file>..." to unstage) deleted: lastorders.php Untracked files: (use "git add <file>..." to include in what will be committed) lastorders.php
© Lightnetics 2024