每个开发人员都应该使用的 Git 命令速查表
GIT 是最广泛使用的分布式开源版本控制系统,它允许您在计算机上本地跟踪和管理对文件所做的更改。
然而,该工具的功能非常强大且广泛,以至于人们很难在其所有可能的命令中迷失。
因此,根据我自己的经验,这里整理了一份GIT 备忘单
,其中包含最重要的和最常用的 GIT 命令,以便于参考。
在这里,您可以下载适用于所有平台的GIT。
GIT 备忘单📋
创造
从现有数据来看,
git init
在当前目录中创建新的存储库git add .
将所有最新更改添加到下一次提交
cd ~/projects/myproject
git init
git add .
来自现有的 repo
git clone
用于从远程服务器克隆存储库
git clone ~/existing/repo ~new/repo
git clone you@host:dir/project.git (default protocol is ssh)
现有本地数据的远程存储库
mkdir repo.git && cd repo.git
git init --bare[--shared=group]
更新
从源获取最新更改
git fetch (this does not merge them)
从源站拉取最新更改
git pull (does a fetch followed by a merge)
应用某人发送给您的补丁
git am -3 patch.mbox (In case of conflict, resolve the conflict and)
git am --resolve
发布
提交所有本地更改
git commit -a
提交先前暂存的更改
git commit -m "descriptive message"
为其他开发人员准备补丁
git format-patch origin
将更改推送至原点
git push [origin][branch]
创建一个版本或里程碑
git tag <version_name>
分支
切换到BRANCH分支
git checkout <BRANCH>
将分支 B1 合并到分支 B2
git checkout <B2>
git merge <B1>
根据HEAD创建分支
git branch <BRANCH>
基于另一个创建分支
git checkout <new><base>
删除分支
git branch -d <branch>
恢复
返回上次提交的状态
git checkout -f | git reset --hard (you cannot undo a hard reset)
恢复最后一次提交
git revert HEAD (Creates a new commit)
恢复特定提交
git revert $id (Creates a new commit)
修复最后一次提交
git commit -a --amend (after editing the broken files)
检出文件的 ID 版本
git checkout <ID><file>
展示
工作目录中的文件已更改
git status
跟踪文件的更改
git diff
ID1 和 ID2 之间的变化
git diff <ID1><ID2>
变更历史
git log
已更改文件的更改历史记录
git whatchanged
谁在何时更改了文件中的内容
git blame <file>
提交通过 ID 来标识
git show <ID>
来自特定 ID 的特定文件
git diff <ID>:<file>
所有当地分行
git branch (star "*" marks the current branch)
搜索模式
git grep<pattern>[path]
这里,
- master 是默认开发分支
- origin 是默认的上游存储库
- HEAD 是当前分支
今天就讲到这里。希望这份速查表能帮你解决一些可能遇到的问题。
当然,它并没有涵盖所有内容,但它是一篇很好的入门文章。
感谢您的阅读,并让我知道您最喜欢的 Git 命令以回应这篇文章,并与您的朋友和同事分享。
文章来源:https://dev.to/ravimengar/a-git-cheatsheet-of-commands-every-developer-should-use-38ma