Git learning Notes (3)--undo changes and delete files

Source: Internet
Author: User

This article mainly records the revocation of errors and the deletion of files in git.

Undo Changes

      here are 3 things.
    1. To change the contents of a file in the workspace, and to discard the workspace changes directly, use the command git checkout-file.
    2. 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.
    3. 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

    1. Use RM to delete the file, then git add filename added to Staging area, Git commit commit.
    2. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.