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>
- 注: 默认的git reset,仅仅会删除
index
的内容 - 注:
reflog
记录所有HEAD的历史,也就是说当使用 reset,checkout等操作的时候,这些操作会被记录在reflog中。 - 注:
git reset --hard
未指定版本号时,执行最近一次commit
的状态,按照那次commit
重设HEAD, index and working tree
。这就是意味着如果在修改之后没有提交commit,直接使用git reset ——hard
,修改会丢失
reset
,reflog
,log
这三个命令搭配起来,做项目,联调的时候是件很爽的事情