git config
git config --global user.name "Your Name"
git config --global user.email "email@example.com"
git status
假設(shè)未執(zhí)行 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
先來(lái)看 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
舉個(gè)例子,說(shuō)明常用的一些參考操作,具體的對(duì)比請(qǐng)看后續(xù)文章
commit的文件着撩,可是使用 git reset --soft HEAD^
來(lái)恢復(fù)到某一個(gè)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 # 此時(shí)會(huì)重設(shè)working tree
如果想要恢復(fù)回退之前的版本锦溪,在git log上是無(wú)法查到的躏精,此時(shí)可以使用 git reflog
git reflog
繼續(xù)執(zhí)行
git reset --hard <HEAD>
- 注: 默認(rèn)的git reset,僅僅會(huì)刪除
index
的內(nèi)容 - 注:
reflog
記錄所有HEAD的歷史李丰,也就是說(shuō)當(dāng)使用 reset,checkout等操作的時(shí)候苗桂,這些操作會(huì)被記錄在reflog中药磺。 - 注:
git reset --hard
未指定版本號(hào)時(shí),執(zhí)行最近一次commit
的狀態(tài)煤伟,按照那次commit
重設(shè)HEAD, index and working tree
癌佩。這就是意味著如果在修改之后沒(méi)有提交commit,直接使用git reset ——hard
,修改會(huì)丟失
reset
,reflog
,log
這三個(gè)命令搭配起來(lái)便锨,做項(xiàng)目驼卖,聯(lián)調(diào)的時(shí)候是件很爽的事情