Fourth, git undo changes and delete files

Undo edit

example:

The contents of readme.txt before modification are:

Git is a version control system.
Git is free software.
Git has a mutable index called stage.

Now start to modify the content of readme.txt, add a line of content My stupid boss still prefers SVN,并且使用git add 和git commit 命令提交修改后的版本。

The content of readme.txt after adding is:

Git is a version control system.

Git is free software.

Git has a mutable index called stage.

My stupid boss still prefers SVN

Now use git reset --hard HEAD^ to go back to the previous version of the repository.

At this time, the content of readme.txt becomes the content before modification:

Git is a version control system.

Git is free software.

Git has a mutable index called stage.


Delete Files

Create a new test.txt file in the learngit directory of the workspace, with custom content:


Then use git add test.txt and git commit -m "add test.txt" to submit the repository:

Delete Files

The first step is to use rm test.txt to delete the file from the workspace:

At this point, you can find that the test.txt file in the workspace has disappeared, and the deletion is successful.

Enter git status to view the repository. At this time, the workspace and the repository are inconsistent. git status tells us that the test.txt file is deleted from the workspace:

The second step is to delete the test.txt file from the repository, use git rm test.txt and git commit -m "remove a test.txt"

If you find that the file has been deleted by mistake, you can return to the previous version if you want to restore the deleted file.

Use git reset --hard HEAD^ to go back to the previous version.

Open the learngit directory and find that test.txt is restored:




Guess you like

Origin blog.csdn.net/li__po/article/details/80427082