tags: GIT Manage changes Undo modification
readme.txtMake a modification, such as adding a line and adding:$ git add readme.txt
$ git status
Located on branch master
Changes to be submitted:
(Use "git reset HEAD <file> ..." To cancel temporary storage)
readme.txtAnd submit:$ git commit -m "git tracks changes"
[master 376d9c0] git tracks changes
1 file changed, 1 insertion(+)
$ git status
Located on branch master
Changes that have not been temporarily stored for submission:
(Use "git add <file> ..." Update the content to be submitted)
(Use "git checkout-<file> ..." Discard work area changes)
Modify: readme.txt
Modifications have not been added for submission (use "git add" and / or "git commit -a")
git add-> Second modification->git commitgit addAfter the order, the first modification in the work area is put into the temporary storage area for preparation. However, the second modification in the work area was not put into the temporary storage area, so,git commitIt is only responsible for submitting the changes in the temporary storage area, that is, the first modification is submitted, and the second modification will not be submitted.git diff HEAD -- readme.txtThe command can check the difference between the latest version in the workspace and the version library:$ git diff HEAD -- readme.txt
diff --git a/readme.txt b/readme.txt
index 76d770f..a9c5755 100644
--- a/readme.txt
+++ b/readme.txt
@@ -1,4 +1,4 @@
Git is a distributed version control system.
Git is free software distributed under the GPL.
Git has a mutable index called stage.
-Git tracks changes.
+Git tracks changes of files.
git addagaingit commit, Or do n’t worry about submitting the first revision, firstgit addThe second modification, and thengit commit, Which is equivalent to submitting the two amendments together.readme.txtAn extra line is added to the file, after submission, usegit statusView, Git will prompt to usegit checkout -- <file>...You can discard changes to the workspace.$ git checkout -- readme.txt
git checkout -- readme.txtMeaning, putreadme.txtAll changes to the file in the workspace are cancelled. There are two cases:
readme.txtIt has not been put into the temporary storage area since the modification. Now, the small modification will return to the same state as the version library;readme.txtAfter it has been added to the temporary storage area, changes have been made. Now, the undo changes will return to the state after being added to the temporary storage area.git commitorgit addState at the time.readme.txtdocument content:$ cat readme.txt
Git is a distributed version control system.
Git is free software distributed under the GPL.
Git has a mutable index called stage.
Git tracks changes of files.
git checkout -- fileIn the order--Very important, no--, It becomesSwitch to another branch, We will encounter again in the branch managementgit checkoutcommand.git addAdded to staging area, incommitFound this problem before, usegit statusView, the modification is just added to the temporary storage area, has not been submitted:$ git status
Located on branch master
Changes to be submitted:
(Use "git reset HEAD <file> ..." To cancel temporary storage)
Modify: readme.txt
git reset HEAD <file>You can unstage the changes in the temporary storage area and put them back in the work area.$ git reset HEAD readme.txt
Cancel temporary changes after reset:
M readme.txt
git statusCheck to make sure that the temporary storage area is clean and the work area is modified$ git status
Located on branch master
Changes that have not been temporarily stored for submission:
(Use "git add <file> ..." Update the content to be submitted)
(Use "git checkout-<file> ..." Discard work area changes)
Modify: readme.txt
Modifications have not been added for submission (use "git add" and / or "git commit -a")
checkoutTo discard changes to the workspace.test.txtFile to Git and submit:$ git add text.txt
$ git commit -m "add text.txt"
[master 89274d2] add text.txt
1 file changed, 2 insertions(+)
create mode 100644 text.txt
rmCommand delete:$ rm text.txt
git statusThe command will tell you immediately which files were deleted:$ git status
Located on branch master
Changes that have not been temporarily stored for submission:
(Use "git add / rm <file> ..." Update the content to be submitted)
(Use "git checkout-<file> ..." Discard work area changes)
Delete: text.txt
Modifications have not been added for submission (use "git add" and / or "git commit -a")
git rmDelete, andgit commit:$ git rm text.txt
rm 'text.txt'
$ git commit -m "delete text.txt"
[master acc1af6] delete text.txt
1 file changed, 2 deletions(-)
delete mode 100644 text.txt
Delete files manually before using
git rm <file>withgit add <file>The effect is the same.
$ git checkout -- test.txt
git checkoutIn fact, the version in the workspace is replaced with the version in the repository, so whether the workspace is modified or deleted, you can "one-click restore".note: Files that have been deleted before being added to the repository cannot be recovered.
Here's a look at git undo changes related commands 1. Undo the changes that have not been submitted. 1) Cancel 1 or 2 files 2) Cancel all txt files 3) Cancel all documents Second, cancel the changes a...
Git Tutorial - Undo Modification Undo the modification (discard the changes in the workspace, no add to the staging area) Undo the modification (the modification has been added to the staging area) Un...
Making mistakes is inevitable, for example, accidentally adding a line of irrelevant content in the readme.txt file: Git is a distributed version control system. Git is free software distributed under...
Naturally, you will not make mistakes. But it's two o'clock in the morning, you are rushing a job report, you added a line to readme.txt Before you were ready to submit, a cup of coffee worked, and yo...
Undo changes in workspace If we add a line in readme.txt We found the last sentence and we want to correct it. We can delete the last line and manually restore the file to the state of the previous ve...
git undoes the modification of a file, divided into two situations: 1.Modified in the work area, but not submitted to the staging area (that is, there is no add)。 For the undo modification of a single...
git checkout -- fileThe modification of the workspace can be discarded: commandgit checkout -- readme.txtMeans, putreadme.txtAll modifications of files in the workspace are undone. There are two situa...
references: 1. You have modified and saved the content of the workspace many times. What if you want to go back to before the modification? Example 1: Modify the README.txt file of the workspace 4 tim...
This command will commit the files in the staging area. If you haven't made any changes since the last commit (for example, if you executed this command immediately after the last commit), the snapsho...
At any stage, you are likely to want to undo some operations. Here, we will learn the basic tools you have done a few changes to undo. Note that some undo action is not reversible. This is one of the ...