Git 备忘单
什么是 git?
Git 是一个免费的开源分布式版本控制系统,旨在快速高效地处理从小型到大型的所有项目。
基本命令:
-
初始化本地 git 仓库
> git init -
检查文件的提交和分支名称
> git status -
将文件添加到暂存区。
> git add FileName.txt -
将所有修改过的文件和新文件添加到暂存区
> git add --all -
将目录的所有文件添加到暂存区
> git add folder/ -
提交更改到本地存储库
> git commit -m "Message to commit" -
提交历史
> git log—— -
获取任何命令的帮助
> git help <Command> -
设置全局用户名
> git config --global user.name "Name" -
显示自上次提交以来未暂存的差异
> git diff -
查看阶段性差异
> git diff --staged -
取消暂存文件,HEAD 指向最后一次提交
> git reset HEAD FileName -
清除自上次提交以来的所有更改
> git checkout -- FileName -
跳过暂存并提交并添加所有跟踪文件的更改。这不会添加新的(未跟踪的)文件
> git commit -a -m "Modify readme" -
重置到暂存区并移动到“HEAD”之前提交
> git reset --soft HEAD^ -
使用新的提交消息添加到最后一次提交
> git commit --amend -m "New Message" -
撤消上次提交和所有更改
> git reset --hard HEAD^ -
撤消最后 2 次提交和所有更改
> git reset --hard HEAD^^ -
添加遥控器
> git remote add <name>origin <address>https://giturl -
显示远程存储库
> git remote -v -
推送到远程
> git push -u <name>origin <branch>master -
删除远程
> git remote rm <name> -
克隆远程存储库
> git clone <address>https://giturl -
创建分支
> git branch <BrancName> -
创建并检出分支
> git checkout -b <BrancName> -
列出可用的分支
> git branch -
列出远程可用分支
> git branch -r -
在分支之间切换
> git checkout <branch name> -
合并两个分支
> git merge <branch name> -
删除分支
> git branch -d <branch name> -
强制删除分支
> git branch -D <branch name> -
获取远程更改
> git pull-
将远程更改获取到本地远程分支
> git fetch -
将本地远程分支的更改合并到本地主分支
> git merge <local branch>
-
-
显示分支比对
> git remote show origin -
删除远程分支
> git push origin :<branch name> -
清理已删除的远程分支
> git remote prune origin -
列出所有标签
> git tag -
创建标签
> git tag -a <Tag Name> -m "Tag message" -
将新标签推送到远程
> git push --tags -
恢复为现有标签。
> git checkout <tag name>
本文最初发表于我的博客git-cheat-sheet
请随意在评论中提及你最喜欢的 git 命令 ❤ 👇
文章来源:https://dev.to/usmslm102/git-cheat-sheet-4f5a
后端开发教程 - Java、Spring Boot 实战 - msg200.com