git study notes --- delete files

In Git, delete operation is a modification, we combat it, to add a new file test.txtto Git and submit:

$ git add test.txt

$ git commit -m "add test.txt"
[master b84166e] add test.txt
 1 file changed, 1 insertion(+)
 create mode 100644 test.txt

  

In general, you usually directly in the file manager to delete useless files, or use the rmcommand delete:

$ rm test.txt

This time, Git know you delete a file, therefore, workspace and repository on the inconsistency, the git statuscommand will tell you which files are deleted immediately:

$ git status
On branch master
Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

	deleted:    test.txt

no changes added to commit (use "git add" and/or "git commit -a")

  

Now you have two options, one sure you want to delete the file repository, then use the command git rmto delete, and git commit:

$ git rm test.txt
rm 'test.txt'

$ git commit -m "remove test.txt"
[master d46f35e] remove test.txt
 1 file changed, 1 deletion(-)
 delete mode 100644 test.txt

  

Now, the file is deleted from the repository.

 

Another case is deleting the wrong, because what else the repository, so you can easily recover accidentally deleted the files to the latest version:

$ git checkout -- test.txt

git checkoutIn fact, the workspace is a replacement version with the version in the repository, regardless of the workspace is modified or deleted, can be "a key to restore."

 Note: never been added to the file repository is deleted and is not recoverable!

summary

Command git rmis used to delete a file. If a file has been submitted to the repository, so you never have to worry about mistakenly deleted, but be careful, you can only restore files to the latest version, you will lose the contents of the most recent commit your changes .

Guess you like

Origin www.cnblogs.com/saryli/p/11368657.html