ref: 工作区和暂存区

撤销修改:
- 小结
场景1:当你改乱了工作区某个文件的内容,想直接丢弃工作区的修改时,用命令$ git checkout -- file
。
场景2:当你不但改乱了工作区某个文件的内容,还添加到了暂存区时,想丢弃修改,分两步,第一步用命令$ git reset HEAD file
,就回到了场景1,第二步按场景1操作。
场景3:已经提交了不合适的修改到版本库时,想要撤销本次提交,参考版本回退一节,不过前提是没有推送到远程库。
命令 | 含义 |
---|---|
$ git config --global user.name "Your Name" | |
$ git config --global user.email "email@example.com" | |
$ git checkout -- <file> |
撤销工作区的修改 |
$ git reset HEAD <file> |
撤销(unstage) 暂存区的修改, 重新放回工作区 |
$ git reset --hard <commit_id> | |
$ git log |
提交(Commit) 历史 |
$ git reflog |
命令历史 |
$ git config --global alias.logx "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit" |
配置查看提交历史命令别名 |
$ git stash branch <branch_name> |
从储藏中创建分支 |
$ git config --global alias.stash-unapply '!git stash show -p | git apply -R' ```
```shell
$ git config --global alias.logx "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
网友评论