git
-
设置email和username
# 设置为全局 git config --global user.email "you@example.com" git config --global user.name "Your Name" # 设置为当前 git config --local user.email "you@example.com" git config --local user.name "Your Name" # 查看当前配置 git config user.email git config user.name # 查看全局配置 git config --global --get user.name git config --global --get user.email # 配置全局代理 git config --global http.proxy 'http://proxyuser:proxypassword@proxy.server.com:port' git config --global https.proxy 'http://proxyuser:proxypassword@proxy.server.com:port' # 取消全局代理 git config --global --unset http.proxy git config --global --unset https.proxy # 仅配置当前代理 git config --local http.proxy 'http://proxyuser:proxypassword@proxy.server.com:port' git config --local https.proxy 'http://proxyuser:proxypassword@proxy.server.com:port' # 取消当前代理 git config --local --unset http.proxy git config --local --unset https.proxy
-
结束符
-
分支切换
-
撤销操作
# 查看提交记录 git log # ---------------------------------- # 未暂存 # 撤销工作目录中未暂存的更改 git checkout -- <file> # 撤销所有未暂存的更改 git checkout . # ---------------------------------- # 已暂存 # 撤销已暂存但未提交的更改 git reset <file> # 取消所有暂存的更改 git reset # ---------------------------------- # 已提交 # 撤销最近的一次提交 # 保留更改,只撤销提交(即将提交从历史记录中移除,但保留工作目录中的更改): git reset --soft HEAD~1 # 不保留更改(即将提交从历史记录中移除,并且将更改从工作目录中删除): git reset --hard HEAD~1 # --hard 选项会丢失所有未提交的更改,请谨慎使用。 # ---------------------------------- # 撤销特定的提交 git revert <commit-hash> # ---------------------------------- # 撤销合并 # 如果最近的提交是一个合并提交,并且您想撤销它,可以使用 git revert 或者 git reset。 # 对于简单的撤销,推荐使用 git revert,因为它不会改变项目的历史记录: git revert -m 1 <merge-commit-hash>