原博引起了大家的吐槽:
從微博看不出該修改是否已經(jīng) commit 屠升,在本地測試這幾種可能:
未add 之前恬惯,切換分支 修改的代碼會丟失;
add 之后,commit之前,切換分支 修改的代碼丟失;
[AntLinkCampus] git status 14:01:51 ? develop ? ??
On branch develop
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: CampusServer/apps/web/conf/app.conf
no changes added to commit (use "git add" and/or "git commit -a")
[AntLinkCampus] git add . 14:02:38 ? develop ? ? ??
[AntLinkCampus] git status 14:02:50 ? develop ? ? ??
On branch develop
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: CampusServer/apps/web/conf/app.conf
commit 之后;
- 新建分支 git branch <new-branch>
- git reset HEAD^ 恢復(fù)上一個版本憋他,
- git checkout -- <file> 取消更改
- 切換分支 git checkout <new-branch>
- 提交自己的更改
[AntLinkCampus] git reset HEAD^ 14:27:54 ? develop ? ??
Unstaged changes after reset:
M CampusServer/apps/web/conf/app.conf
[AntLinkCampus] git status 14:28:17 ? develop ? ? ??
On branch develop
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: CampusServer/apps/web/conf/app.conf
no changes added to commit (use "git add" and/or "git commit -a")
[AntLinkCampus] git checkout -- CampusServer/apps/web/conf/app.conf 14:28:50 ? develop ? ? ??
[AntLinkCampus] git status 14:29:00 ? develop ? ??
On branch develop
nothing to commit, working directory clean
也可以使用以下方法:利用 git stash
[AntLinkCampus] git stash 14:52:44 ? develop ? ? ??
Saved working directory and index state WIP on develop: e3be7d3 update
HEAD is now at e3be7d3 update
[AntLinkCampus] git checkout -b ch 14:52:59 ? develop ? ??
Switched to a new branch 'ch'
[AntLinkCampus] git status 14:53:08 ? ch ?
On branch ch
nothing to commit, working directory clean
[AntLinkCampus] git stash pop 14:53:35 ? ch ?
On branch ch
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: CampusServer/apps/web/conf/app.conf
no changes added to commit (use "git add" and/or "git commit -a")
Dropped refs/stash@{0} (e7a4c7e7a126d47ace94184d7a9443eff41d7e84)
[AntLinkCampus] git add . 14:54:01 ?
[AntLinkCampus] git commit -m 'update' 14:54:01 ?
切回主分支撤銷修改
[AntLinkCampus] git checkout develop 14:54:01 ? ch ? ?
M CampusServer/apps/web/conf/app.conf
Switched to branch 'develop'
[AntLinkCampus] git status 14:55:26 ? develop ? ? ??
On branch develop
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: CampusServer/apps/web/conf/app.conf
no changes added to commit (use "git add" and/or "git commit -a")
[AntLinkCampus] git checkout -- CampusServer/apps/web/conf/app.conf 14:55:33 ? develop ? ? ??