This article mainly records the revocation of errors and the deletion of files in git.
Undo Changes
here are 3 things.
- To change the contents of a file in the workspace, and to discard the workspace changes directly, use the command git checkout-file.
- Not only to change the contents of a file in the workspace, but also add to the staging area, want to discard changes, two steps, the first step with the command git reset HEAD file, back to 1, the second step, according to 1 operation.
- If you have submitted an inappropriate modification to the repository, you want to revoke this commit, and you can roll back the version, but only if it is not pushed to the remote library.
// First Revocation: Workspace revocation VI Readme.txt//Workspace error has not been added to staging area [email protected]:~/joe/ The branch master has not yet been staged for commit changes: "git add <file> " update the content to be submitted ) "
git checkout--<file>, ... . "
Discard Workspace Changes :"git add""git commit-a" ) [email protected]:
git checkout--
Readme.txt [Email protected]:vi readme.txt// Second revocation: Staging area undo VI readme.txt [ Email protected]:~/joe/git add readme.txt //The wrong file has been submitted to staging area [email protected]:~/joe/ learngit$ git status is at the branch master to commit the change:"
git reset HEAD <file> "
withdrawal Staging area ) Modified: Readme.txt[email protected]:~/joe/learngit$ git reset HEAD readme.txt reset after withdrawal of staging area change: M readme.txt[email protected]:~/joe/learngit$VIReadme.txt [email protected]:~/joe/learngit$ git status//Withdraw staging area, the changes that you need to use checkout discard workspace are in changes that branch master has not yet staged for submission: (Using"git add <file>, ... ."update the content to be submitted) (using"git checkout--<file>, ... ."Discard workspace changes) Modified: Readme.txt Modification has not yet joined the commit (using"git add"and/or"git commit-a") [email protected]:~/joe/learngit$
git checkout--
Readme.txt [Email protected]:vi readme.txt// Third has been submitted, use version fallback (Learn note 2)
Deletion of files
- Use RM to delete the file, then git add filename added to Staging area, Git commit commit.
- Use git RM filename directly, without git add direct git commit.
// The first method of git rm file ls abc.c readme.txt[email protected]:
git rm
ABC.C RM ' ABC.C ' [email protected]:~/joe/git status at branch master to commit the change: " git reset HEAD <file> " withdraw staging area) Delete: abc.c[email protected]:
git commit-m "del abc"
[Master 020f927] del ABC1 fileChanged0Insertions (+),0Deletions (-) Delete Mode100644Abc.c[email protected]:~/joe/learngit$ git status in branch Master no file to submit, clean workspace [email protected]:~/joe/learngit$lsReadme.txt//The second method of RM file[email protected]:~/joe/learngit$lsAB.C readme.txt[email protected]:~/joe/learngit$RM AB.C[email protected]:~/joe/learngit$lsReadme.txt[email protected]:~/joe/learngit$ git status is in a change that branch master has not yet staged for submission: (Using"git add/rm <file>"update the content to be submitted) (using"git checkout--<file>, ... ."Discard workspace changes) Delete: AB.C modification has not yet joined the commit (using"git add"and/or"git commit-a") [email protected]:~/joe/learngit$ git add ab.c [email protected]:~/joe/learngit$ git status is at the branch master to commit the change: (Using"git reset HEAD <file>"withdraw Staging area) Delete: Ab.c[email protected]:~/joe/learngit$
git commit-m "del ab.c"
1 file 0 0 Deletions (-100644 ab.c[email protected]:~/joe/git status in branch Master no files to submit, clean workspace
Git learning Notes (3)--undo changes and delete files