分类 |
命令 |
功能 |
说明 |
本地修改 |
git init |
初始化仓库 |
|
git status |
查看工作区状态 |
| |
git diff <file_name> |
查看修改内容 |
| |
git add [-f] <file_name> |
添加修改文件 |
“-f”:强制添加 | |
git rm <file_name> |
删除文件 |
执行之后需要”git commit” | |
git commit -m “message” |
提交修改 |
| |
撤销修改 |
git checkout --<file_name> |
丢弃工作区的修改 |
“--”不可省略 |
git reset HEAD <file_name> |
撤销暂存区的修改 |
回退到工作区 | |
版本回退 |
git log [--pretty=oneline] |
查看提交历史 |
|
git reflog |
查看命令历史 |
帮助“重返未来” | |
git reset --hard <commit_id> |
回退版本 |
HEAD(当前版本),HEAD^(上一版本) | |
分支管理 |
git branch |
查看分支 |
|
git branch <branch_name> |
创建分支 |
| |
git checkout <branch_name> |
切换分支 |
| |
git checkout -b <branch_name> |
创建+切换分支 |
| |
git checkout -b <branch_name> origin/<branch_name> |
创建远程分支到本地 |
| |
git merge [--no-ff -m “message”] <branch_name> |
合并到当前分支 |
“--no-ff”:禁用Fast forward | |
git branch -d <branch_name> |
删除分支 |
| |
git branch -D <branch_name> |
强行删除未合并的分支 |
| |
git log --graph --pretty=oneline --abbrev-commit |
查看分支合并图 |
| |
远程仓库 |
git push [-u] origin <branch_name> |
推送分支到远程仓库 |
“-u”:关联分支(第一次使用) |
git branch --set-upstream <branch_name> origin/<branch_name> |
设置本地分支与远程分支的链接 |
未设置将导致pull不成功 | |
git pull |
抓取分支 |
| |
git clone <repository_url> |
从远程仓库克隆 |
| |
git remote [-v] |
查看远程仓库信息 |
“-v”:查看详细信息 | |
工作现场 |
git stash |
存储工作现场 |
|
git stash list |
查看工作现场 |
| |
git stash apply [stash_no] |
恢复工作现场 |
并未删除工作现场 | |
git stash drop |
删除工作现场 |
| |
git stash pop |
恢复+删除工作现场 |
| |
标签管理 |
git tag |
查看所有标签 |
|
git tag [-a] <tag_name> [-m “message”] [commit_id] |
打标签(默认最新提交的commit) |
“-s”:用私钥签名标签 | |
git show <tag_name> |
查看标签信息 |
| |
git tag -d <tag_name> |
删除本地标签 |
| |
git push origin <tag_name> |
推送标签到远程库 |
| |
git push origin --tags |
一次性推送所有未推送的标签 |
| |
git push origin :refs/tags/<tag_name> |
删除远程库上的标签 |
| |
自定义 |
git config --global color.ui true |
显示颜色 |
|
git check-ignore -v <file_name> |
检查gitignore规则 |
| |
git config --global alias.<short_name> <cmd_name> |
配置命令别名 |
显示最后一次提交:git config --global alias.last 'log -1' |
Git命令简明清晰版
最新推荐文章于 2025-03-28 09:00:00 发布