theme: condensed-night-purple
highlight: an-old-hope
如果你也和我女朋友一样总是忘记Git命令,觉得记忆Git命令是很枯燥和麻烦的事情。我写了一个包含了40 条常用Git命令的清单。你一定要收藏起来,当你忘记Git命令的时候,就可以打开来查看啦!!!
git init <directory>
<directory>
目录是可选的。如果没有指定,默认使用当前目录。
git clone <url>
git add <file>
如果要添加当前目录中的所有文件,请使用.
代替<file>
.
git add .
git commit -m "<message>"
如果您想添加跟踪文件的所有更改(包括最新的修改)并提交
git commit -a -m "<message>"
# or
git commit -am "<message>"
git reset <file>
git mv <current path> <new path>
git rm <file>
你也可以仅使用标志符将其从暂存区中删除--cached
git rm --cached <file>
main
origin
HEAD
HEAD^
或HEAD~1
HEAD^^
或HEAD~2
git branch
常用的标识符:
-a
:查询所有分支(本地和远程)-r
: 查询远程分支-v
: 查询最后一次提交的分支*git branch <branch>
您可以创建一个新分支并使用checkout
命令切换到你新创建的分支下。
git checkout -b <branch>
git checkout <branch>
git branch -d <branch>
您还可以使用标识符-D
强制删除分支。
git branch -D <branch>
git merge <合并到当前分支>
常用的标识符:
--no-ff
:创建合并并且提交--squash
:将指定分支的所有commit
记录合并成一个不建议使用--squash
?标识符,因为它会将所有提交合并成一个提交,从而导致提交历史记录混乱。
Rebase变基是将一系列提交移动或组合到新的基础提交的过程
<p align=center><img src="https://p1-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/e0ed7c4171084c66933074bc91516ce2~tplv-k3u1fbpfcp-watermark.image?" alt="image.png" /></p>
git rebase <branch to rebase from>
git checkout <commit id>
git revert <commit id>
git reset <commit id>
你还可以添加--hard
标识符来删除所有更改,但是一般不建议使用。
git reset --hard <commit id>
git status
git log
git diff
你还可以使用--staged
标识符来显示对暂存文件的更改。
git diff --staged
git diff <commit id 01> <commit id 02>
stash允许您临时存储更改而不提交到代码仓库 。
git stash
我们还可以向stash添加一条说明信息。
git stash save "<message>"
git stash list
拉取stash不会把当前的stash从stash列表中删除。
git stash apply <stash id>
如果不指定<stash id>
,将应用最新的stash(适用于所有类似的stash命令)
你还可以使用格式stash@{<index>}
来应用stash(适用于所有类似的stash命令)
git stash apply stash@{0}
git stash drop <stash id>
git stash clear
git stash pop <stash id>
git stash show <stash id>
git remote add <remote name> <url>
git remote
添加一个-v
标识符用来查询远程存储库的URL。
git remote -v
git remote remove <remote name>
git remote rename <old name> <new name>
git fetch <remote name>
git fetch <remote name> <branch>
git pull <remote name> <branch>
git push <remote name>
git push <remote name> <branch>
我正在参与2023腾讯技术创作特训营第三期有奖征文,组队打卡瓜分大奖!
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。