开始使用 Git 所需的 51 个 git 命令🔥
版本控制(Git)基础知识
嗨!在本篇博客教程中,我将列出你开启 GIT 之旅所需的所有必要且唯一的命令。你可以收藏本博客,并在需要时随时查看。
检查 git 配置
git config -l
设置你的 git 用户名
git config --global user.name "pramit"
设置电子邮件
git config --global user.email "pramit@aviyel.com"
缓存凭证
git config --global credential.helper cache
初始化存储库
git init
将文件名添加到暂存区
git add file_name
将所有文件添加到暂存区
git add .
仅将某些文件添加到暂存区
例如添加所有以“comp”开头的文件
git add comp*
检查 repo 状态
git status
提交更改
git commit
提交更改并附带一条消息
git commit -m "YOOOO!!! This is a message"
添加到暂存区并提交更改,并在其中添加一条消息
git commit -a -m "YOOOO!!! This is another message"
查看提交历史记录
git log
提交历史记录和以下文件更改
git log -p
在 git 中显示特定的提交
git show commit_id
变化统计
git log --stat
使用 diff 提交之前所做的更改
git diff
git diff some_file.js
git diff --staged
删除已跟踪的文件
git rm filename
在 git 中重命名文件
git mv oldfilename newfilename
恢复未暂存的更改
git checkout file_name
恢复阶段性更改
git reset HEAD filename
git reset HEAD -p
修改并添加对最近提交的更改
git commit --amend
回滚最后一次提交
git revert HEAD
恢复先前的提交
git revert comit_id_here
创建新分支
git branch branch_name
列出 git 中的分支
git branch
创建分支并立即切换
git checkout -b branch_name
删除 git 中的分支
git branch -d branch_name
合并
git merge branch_name
在 git 中将日志提交为图表
git log --graph --oneline
将所有分支的提交日志以图表形式呈现在 git 中
git log --graph --oneline --all
中止冲突的合并
git merge --abort
添加远程存储库
git add remote https://repository_name.com
查看远程仓库 URL
git remote -v
获取有关远程仓库的更多信息
git remote show origin
将更改推送到远程存储库
git push
从远程仓库拉取更改
git pull
检查 git 当前正在跟踪的远程分支
git branch -r
获取远程仓库更改
git fetch
远程仓库的当前提交日志
git log origin/main
将远程仓库与本地仓库合并
git merge origin/main
在 Git 中获取远程分支的内容而不自动合并
git remote update
将新分支推送到远程存储库
git push -u origin branch_name
在 git 中删除远程分支
git push --delete origin branch_name
GIT 变基
(使用 git rebase 将完成的工作从一个分支转移到另一个分支)
git rebase branch_name
在 git 中强制推送请求:(非常危险)
git push -f
Git 技巧和窍门
空白提交
git commit --allow-empty -m "yooo"
美化日志
git log --pretty=oneline --graph --decorate
清理本地分支
git config --global fetch.prune true
- 你可以清理已合并的本地分支
git branch --merged master | grep -v "master" | xargs -n 1 git branch -d
指定 Git 应忽略的故意未跟踪的文件的文件
.gitignore
编码愉快!!
如果您是项目维护者、贡献者或只是开源爱好者,请关注@aviyelHQ或在 Aviyel 上注册以获得早期访问权限。
加入 Aviyel 的 Discord => Aviyel 的世界
推特 =>[ https://twitter.com/AviyelHq ]
文章来源:https://dev.to/aviyel/51-git-commands-that-youll-ever-need-to-get-started-with-git-34d5