20 个最常用的 Git 命令,你都会用吗()
在这篇文章中,我将介绍在使用 Git 时最常使用的 20 个命令。
以下是这些Git命令:
- git config
- git init
- git clone
- git add
- git commit
- git diff
- git reset
- git status
- git rm
- git log
- git show
- git tag
- git branch
- git checkout
- git merge
- git remote
- git push
- git pull
- git stash
Git 命令
git config
用法:git config –global user.name “[name]”
用法:git config –global user.email “[email address]”
该命令将分别设置提交代码的用户名和电子邮件地址。

文章图片
git init
用法:git init [repository name]
【20 个最常用的 Git 命令,你都会用吗()】该命令可用于创建一个新的代码库。

文章图片
git clone
用法:git clone [url]
该命令可用于通过指定的URL获取一个代码库。

文章图片
git add
用法:git add [file]
该命令可以将一个文件添加至stage(暂存区)。

文章图片
用法:git add *
该命令可以将多个文件添加至stage(暂存区)。

文章图片
git commit
用法:git commit -m “[ Type in the commit message]”
该命令可以在版本历史记录中永久记录文件。

文章图片
用法:git commit -a
该命令将提交git add命令添加的所有文件,并提交git add命令之后更改的所有文件。

文章图片
git diff
用法:git diff
该命令可以显示尚未添加到stage的文件的变更。

文章图片
用法:git diff –staged
该命令可以显示添加到stage的文件与当前最新版本之间的差异。

文章图片
用法:git diff [first branch] [second branch]
该命令可以显示两个分支之间的差异。

文章图片
git reset
用法:git reset [file]
该命令将从stage中撤出指定的文件,但可以保留文件的内容。

文章图片
用法:git reset [commit]
该命令可以撤销指定提交之后的所有提交,并在本地保留变更。

文章图片
用法:git reset –hard [commit]
该命令将丢弃所有的历史记录,并回滚到指定的提交。

文章图片
git status
用法:git status
该命令将显示所有需要提交的文件。

文章图片
git rm
用法:git rm [file]
该命令将删除工作目录中的文件,并将删除动作添加到stage。

文章图片
git log
用法:git log
该命令可用于显示当前分支的版本历史记录。

文章图片
用法:git log –follow[file]
该命令可用于显示某个文件的版本历史记录,包括文件的重命名。

文章图片
git show
用法:git show [commit]
该命令经显示指定提交的元数据以及内容变更。

文章图片
git tag
用法:git tag [commitID]
该命令可以给指定的提交添加标签。

文章图片
git branch
用法:git branch
该命令将显示当前代码库中所有的本地分支。

文章图片
用法:git branch [branch name]
该命令将创建一个分支。

文章图片
用法:git branch -d [branch name]
该命令将删除指定的分支。

文章图片
git checkout
用法:git checkout [branch name]
你可以通过该命令切换分支。

文章图片
用法:git checkout -b [branch name]
你可以通过该命令创建一个分支,并切换到新分支上。

文章图片
git merge
用法:git merge [branch name]
该命令可以将指定分支的历史记录合并到当前分支。

文章图片
git remote
用法:git remote add [variable name] [Remote Server Link]
你可以通过该命令将本地的代码库连接到远程服务器。

文章图片
git push
用法:git push [variable name] master
该命令可以将主分支上提交的变更发送到远程代码库。

文章图片
用法:git push [variable name] [branch]
该命令可以将指定分支上的提交发送到远程代码库。

文章图片
用法:git push –all [variable name]
该命令可以将所有分支发送到远程代码库。

文章图片
用法:git push [variable name] :[branch name]
该命令可以删除远程代码库上的一个分支。

文章图片
git pull
用法:git pull [Repository Link]
该命令将获取远程服务器上的变更,并合并到你的工作目录。

文章图片
git stash
用法:git stash save
该命令将临时保存所有修改的文件。

文章图片
用法:git stash pop
该命令将恢复最近一次stash(储藏)的文件。

文章图片
用法:git stash list
该命令将显示stash的所有变更。

文章图片
用法:git stash drop
该命令将丢弃最近一次stash的变更。

文章图片
原文:https://dzone.com/articles/to... \
作者:Sahiti Kappagantula \
译者:弯月,责编:屠敏 \
出品:CSDN(ID:CSDNnews)
近期热文推荐:
1.1,000+ 道 Java面试题及答案整理(2021最新版)
2.别在再满屏的 if/ else 了,试试策略模式,真香!!
3.卧槽!Java 中的 xx ≠ null 是什么新语法?
4.Spring Boot 2.5 重磅发布,黑暗模式太炸了!
5.《Java开发手册(嵩山版)》最新发布,速速下载!
觉得不错,别忘了随手点赞+转发哦!
推荐阅读
- 昨夜小楼听风
- 为什么你的路演总会超时()
- 深入理解Go之generate
- 遗憾是生活的常态,但孝顺这件事,我希望每一个人都不留遗憾
- 标签、语法规范、内联框架、超链接、CSS的编写位置、CSS语法、开发工具、块和内联、常用选择器、后代元素选择器、伪类、伪元素。
- 唱歌教学(导致嗓音损坏的几个常见的错误唱歌方法!)
- 迷茫是人生常态
- Hive常见问题汇总
- 数组常用方法一
- 【原创】君子之心,常怀敬畏