Git常用命令总结

2016-06-09  本文已影响17人  郝翔

git config

git config --global user.name "Your Name"
git config --global user.email "email@example.com"

git status

假设未执行 add 操作

git status
On branch 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:   file1

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

如果有 git add 追踪的文件,但是未 commit

git status
等待commit
On branch banana
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    modified:   file1
    modified:   file2

git reset

先来看 usage:

usage: git reset [--mixed | --soft | --hard | --merge | --keep] [-q] [<commit>]
   or: git reset [-q] <tree-ish> [--] <paths>...
   or: git reset --patch [<tree-ish>] [--] [<paths>...]

    -q, --quiet           be quiet, only report errors
    --mixed               reset HEAD and index
    --soft                reset only HEAD
    --hard                reset HEAD, index and working tree
    --merge               reset HEAD, index and working tree
    --keep                reset HEAD but keep local changes
    -p, --patch           select hunks interactively
    -N, --intent-to-add   record only the fact that removed paths will be added later

举个例子,说明常用的一些参考操作,具体的对比请看后续文章

commit的文件,可是使用 git reset --soft HEAD^ 来恢复到某一个commit

git reset --soft HEAD^
git status #Changes to be committed,use "git reset HEAD <file>..." to unstage
git reset -q file #Changes not staged for commit
git reset --hard # 此时会重设working tree

如果想要恢复回退之前的版本,在git log上是无法查到的,此时可以使用 git reflog

git reflog

继续执行

git reset --hard <HEAD>

reset,reflog,log这三个命令搭配起来,做项目,联调的时候是件很爽的事情

上一篇 下一篇

猜你喜欢

热点阅读