文章目录
git config
Please tell me who you are
git config --global user.email hanjiale@mail.ustc.edu.cn
git config --global user.name hanjiale
git clone
- [本地文件夹名],不写默认使用原文件夹名。
- [远程主机名],不写默认为 origin。
git clone [版本库的网址] [本地文件夹名] -o [远程主机名]
git remote
添加远程主机,[主机名]一般使用 origin
git remote add [主机名] [版本库的网址]
查看远程主机信息
git remotve -v
修改远程主机名
git remote rename [原主机名] [新主机名]
修改远程主机地址
git remote set-url [主机名] [新主机地址]
删除远程仓库
git remote rm [仓库名]
git branch
查看本地分支信息
git branch -v
新建本地分支
git branch [分支名]
分支重命名
git branch -m [旧分支名] [新分支名]
删除本地分支
git branch -d [分支名]
查看本地及远端所有分支
git branch -a
删除远端分支
git push origin --delete [远程分支名]
git status
查看状态
git add
提交未跟踪的、修改的和删除的文件到暂存区
git add --all
提交未跟踪的、修改的文件到暂存区,不提交删除的文件
git add .
提交修改的和删除的文件到暂存区,不提交未跟踪的文件
git add -u
git restore
文件修改后,还未提交到暂存区,想撤销修改
git restore [file]
文件修改后,已提交到暂存区,还未commit,想撤销修改
git restore --staged [file] //从暂存区撤销提交,但修改未撤销
git restore [file] //撤销修改
git commit
提交
git commit -m "..."
修改上一次提交
git commit --amend -m "..."
git fetch
在本地新建一个分支,并将远程仓库的master分支代码下载到本地分支
git fetch [远程仓库名] master:[本地分支名]
git diff
显示不同版本所有 有差异的文件的列表
git diff branch1 branch2 --stat
显示不同版本在同一路径下有差异的文件的列表
git diff branch1 branch2 --stat [pathname]
比较不同版本同一文件的的差异
git diff branch1 branch2 [filename]
比较不同版本所有文件的差异
git diff branch1 branch2
比较该版本与另一分支所有文件的差异
git diff branch1
git merge
合并分支
git merge [分支名]
merge 后出现大量 conflict,发现情况不对 🤨,想撤销合并
git merge --abort
对于添加了.gitignore的文件,仍然会被trace到的解决方法:
git rm --cached file_name
git rm -rf --cached dir_name
原因是添加了 .gitignore 忽略这些路径后,由于这个路径是已经增加到过仓库管理中,所以尽管已经在 ignore 列表里,依然会被 git trace 到每个文件的变化。这时只需删除已缓存的trace就可以了。