前20大主要Git命令和示例

如果你知道Git是什么,以及它是如何工作的,那么该看看如何使用前20个Git命令和示例。

包涵以下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 config

用法:git config -global user.name“[name]”

用法:git config -global user.email“[email address]”

此命令分别设置要与提交一起使用的作者姓名和电子邮件地址。

git init

用法: git init [repository name]

此命令用于启动新存储库。

git clone

用法: git clone [url]

此命令用于从现有URL获取存储库。

git add

用法: git add [file]

此命令将文件添加到暂存区域。

用法: git add *

此命令将一个或多个添加到暂存区域。

git commit

用法:git commit -m“[Type in the commit message]”

此命令在版本历史记录中永久记录或快照文件。

用法: git commit -a

此命令使用git add命令提交你添加的所有文件,并提交自此以后你更改的所有文件。

git diff

用法:git diff

此命令显示尚未暂存的文件差异。

用法:git diff -staged

此命令显示暂存区域中的文件与当前的最新版本之间的差异。

用法:git diff [first branch] [second branch]

此命令显示所提到的两个分支之间的差异。

git reset

用法:git reset [file]

此命令取消暂存文件,但它保留文件内容。

用法:git reset [commit]

此命令撤消指定提交后的所有提交,并在本地保留更改。

用法:git reset -hard [commit]

此命令会丢弃所有历史记录并返回指定的提交。

git status

用法:git status

此命令列出了必须提交的所有文件。

git rm

用法:git rm [file]

此命令从工作目录中删除该文件并分阶段删除。

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

此命令将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

此命令可恢复最近隐藏的文件。

用法:git stash list

此命令列出所有存储的更改集。

用法:git stash drop

此命令会丢弃最近隐藏的变更集。

举报
评论 0