Notes Use git (II)

Undo operation

In the course of recent use git, sometimes I encountered such a problem: habitual "add -A", which will be all the modifications are added to the staging area, but had to modify two files do not want to add Yeah, how to do this? git provides methods to undo operations. such as:

Cancel the changes have been temporarily stored

As I said earlier, the habit of "add -A" temporarily do not want to add the changes added to the staging area. The changes have been canceled staging of the method, git has been in every time you usegit status View the file when the state gives a solution,

➜  hexo-theme git:(master) ✗ git status
On branch master
Your branch is ahead of 'origin/master' by 2 commits.
  (use "git push" to publish your local commits)

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    modified:   processing/README.md
    modified:   processing/layout/_partial/navigation.jade
    modified:   processing/layout/_widget/archive.jade
    modified:   processing/layout/_widget/categories.jade
    modified:   processing/source/css/_base/base.scss
    modified:   processing/source/css/_base/variables.scss
    modified:   processing/source/css/_partial/navigation.scss
    modified:   processing/source/css/style.scss

You can use git reset HEAD ... a way to cancel the staging.

➜  hexo-theme git:(master) ✗ git reset HEAD *
Unstaged changes after reset:
M   processing/README.md
M   processing/layout/_partial/navigation.jade
M   processing/layout/_widget/archive.jade
M   processing/layout/_widget/categories.jade
M   processing/source/css/_base/base.scss
M   processing/source/css/_base/variables.scss
M   processing/source/css/_partial/navigation.scss
M   processing/source/css/style.scss

Next time you usegit status View file status can be seen

➜  hexo-theme git:(master) ✗ git status
On branch master
Your branch is ahead of 'origin/master' by 2 commits.
  (use "git push" to publish your local commits)

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

    modified:   processing/README.md
    modified:   processing/layout/_partial/navigation.jade
    modified:   processing/layout/_widget/archive.jade
    modified:   processing/layout/_widget/categories.jade
    modified:   processing/source/css/_base/base.scss
    modified:   processing/source/css/_base/variables.scss
    modified:   processing/source/css/_partial/navigation.scss
    modified:   processing/source/css/style.scss

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

It can be seen now all the changes have not been temporarily stored.

Cancel changes to the document

Once when I was repairing a bug, modify a local file repository, is not yet complete, companion told me he had made the desired changes, and has been submitted to the remote. I stopped the work at hand, ready to pull, this time realized that if direct pull, merge, when bound to conflict, because my colleagues and I almost simultaneously modify the same file in the same place. But I have modified the file in many places, blindly CTRL + Z is difficult to solve the problem, this time I need to return my modified file to the state before the modification. Chances are very good at executiongit status When, also it gives a specific withdrawal method.

➜  hexo-theme git:(master) git status
On branch master
Your branch is up-to-date with 'origin/master'.

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

    modified:   processing/layout/_widget/archive.jade
    modified:   processing/layout/_widget/categories.jade
    modified:   processing/layout/_widget/tags.jade
    modified:   processing/layout/layout.jade
    modified:   processing/source/css/_base/base.scss

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

Usegit checkout -- <filename> To cancel the change in the working directory.

➜  hexo-theme git:(master) ✗ git checkout -- *
➜  hexo-theme git:(master) git status
On branch master
Your branch is up-to-date with 'origin/master'.

nothing to commit, working directory clean

The effect is obvious! ! This command some danger, all changes to files are gone. If one is not careful modification will discard their needs, and it can only cry ......

Last revised submission

Sometimes when submitting found himself missing or multi-select several files, or by submitting information was wrong, just want to undo a commit, you can use--amend This option, resubmit

➜  hexo-theme git:(master) ✗ git add -A
➜  hexo-theme git:(master) ✗ git commit -m "commit wrong"
[master ebcbab2] commit wrong
 4 files changed, 78 insertions(+), 106 deletions(-)
 rewrite processing/source/css/_base/base.scss (64%)
 

Found himself submitted a "commit wrong" error message submission, do not be too nervous, enter the command

git commit --amend 

After that, it will jump to the command line in vim, prompting you to modify the submitted information. Unless pushed to the remote end, everything that ~

Intelligent Recommendation

Use of GitHub and git (notes)

GitHub common concepts 1, Repository warehouse That is, their own projects, each project corresponds to a warehouse 2, Star collection Collect other people's projects 3, Fork copy clone project Clone ...

[Git notes] basic use

Configuration before initial run Git comes with a git config tool to help set configuration variables that control the look and behavior of Git. These variables are stored in three different locations...

Git use study notes

Use of the environment: win10 Use Version: First, know Git Git is the world's most advanced distributed version control system, then it has no central server, each person's computer is a complete repo...

Use git notes

  GIT use notes   1. Create a server git repository git init --bare Creating a repository directory as a server, such as server   2. Cloning a remote server in the local repository git ...

svn and git use notes

This happened last week several things: Google released SHA-1 collision secure encryption examples Cloudflare leaked encrypted data networking session linux kernel vulnerability CVE-2017-6074 Encrypti...

More Recommendation

Use a git notes:

Get code into Bitbucket fast using the command line Set up your local directory Set up Git on your machine if you haven't already. Create your first file, commit, and push...

GIT use and error Notes

As a very useful free version management tools, GIT has many advantages. Recent work has encountered a problem a lot of GIT. Recently I took over a project, the first time the source code uploaded to ...

Git everyday use Notes

Create a git repository Creating a branch Operation remote branch Version rollback   Reproduced in: https: //my.oschina.net/u/3398936/blog/1615916...

[] Use git notes

Pull remote branch If you can not pull git project, may not be updated telematics...

Git use notes to organize

Reference article Install git Install git tortoise Set username and password $ git config --global user.name "xxx" $ git config --global user.email "[email protected]" Generate key ssh-ke...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top