search
HomeDevelopment ToolsgitA complete list of commonly used git commands [recommended collection]

Recommended: "git tutorial"

1. Commonly used git commands

1.Commonly used

git remote add origin git@github.com:yeszao/dofiler.git         # 配置远程git版本库
git pull origin master                                          # 下载代码及快速合并 
git push origin master                                          # 上传代码及快速合并
git fetch origin                                                # 从远程库获取代码

git branch                                                      # 显示所有分支
git checkout master                                             # 切换到master分支
git checkout -b dev                                             # 创建并切换到dev分支
git commit -m "first version"                                   # 提交

git status                                                      # 查看状态
git log                                                         # 查看提交历史

git config --global core.editor vim                             # 设置默认编辑器为vim(git默认用nano)
git config core.ignorecase false                                # 设置大小写敏感
git config --global user.name "YOUR NAME"                       # 设置用户名
git config --global user.email "YOUR EMAIL ADDRESS"             # 设置邮箱

2. Alias ​​alias

git config --global alias.br="branch"                 # 创建/查看本地分支
git config --global alias.co="checkout"               # 切换分支
git config --global alias.cb="checkout -b"            # 创建并切换到新分支
git config --global alias.cm="commit -m"              # 提交
git config --global alias.st="status"                 # 查看状态
git config --global alias.pullm="pull origin master"  # 拉取分支
git config --global alias.pushm="push origin master"  # 提交分支
git config --global alias.log="git log --oneline --graph --decorate --color=always" # 单行、分颜色显示记录
git config --global alias.logg="git log --graph --all --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(bold white)— %an%C(reset)%C(bold yellow)%d%C(reset)' --abbrev-commit --date=relative" # 复杂显示

3. Create a repository

git clone <url>                 # 克隆远程版本库
git init                        # 初始化本地版本库

4. Modify and submit

git status                      # 查看状态
git diff                        # 查看变更内容
git add .                       # 跟踪所有改动过的文件
git add <file>                  # 跟踪指定的文件
git mv <old> <new>              # 文件改名
git rm <file>                   # 删除文件
git rm --cached <file>          # 停止跟踪文件但不删除
git commit -m “commit message”  # 提交所有更新过的文件
git commit --amend              # 修改最后一次提交

5. View history

git log                         # 查看提交历史
git log -p <file>               # 查看指定文件的提交历史
git blame <file>                # 以列表方式查看指定文件的提交历史

6. Undo

git reset --hard HEAD           # 撤消工作目录中所有未提交文件的修改内容
git reset --hard <version>      # 撤销到某个特定版本
git checkout HEAD <file>        # 撤消指定的未提交文件的修改内容
git checkout -- <file>          # 同上一个命令
git revert <commit>             # 撤消指定的提交分支与标签

7. Branches and tags

git branch                      # 显示所有本地分支
git checkout <branch/tag>       # 切换到指定分支或标签
git branch <new-branch>         # 创建新分支
git branch -d <branch>          # 删除本地分支
git tag                         # 列出所有本地标签
git tag <tagname>               # 基于最新提交创建标签
git tag -a "v1.0" -m "一些说明"  # -a指定标签名称,-m指定标签说明
git tag -d <tagname>            # 删除标签

git checkout dev                # 合并特定的commit到dev分支上
git cherry-pick 62ecb3

8. Merge and rebase

git merge <branch>              # 合并指定分支到当前分支
git merge --abort               # 取消当前合并,重建合并前状态
git merge dev -Xtheirs          # 以合并dev分支到当前分支,有冲突则以dev分支为准
git rebase <branch>             # 衍合指定分支到当前分支

9. Remote operations

git remote -v                   # 查看远程版本库信息
git remote show <remote>        # 查看指定远程版本库信息
git remote add <remote> <url>   # 添加远程版本库
git remote remove <remote>      # 删除指定的远程版本库
git fetch <remote>              # 从远程库获取代码
git pull <remote> <branch>      # 下载代码及快速合并
git push <remote> <branch>      # 上传代码及快速合并
git push <remote> :<branch/tag-name> # 删除远程分支或标签
git push --tags                 # 上传所有标签

10. Packaging

git archive --format=zip --output ../file.zip master    # 将master分支打包成file.zip文件,保存在上一级目录
git archive --format=zip --output ../v1.2.zip v1.2      # 打包v1.2标签的文件,保存在上一级目录v1.2.zip文件中
git archive --format=zip v1.2 > ../v1.2.zip             # 作用同上一条命令

11. Global and local configuration

  • Global configuration is saved in:$Home/.gitconfig
  • Local warehouse configuration is saved in:. git/config

#12. Remote and local merge

git init                              # 初始化本地代码仓
git add .                             # 添加本地代码
git commit -m "add local source"      # 提交本地代码
git pull origin master                # 下载远程代码
git merge master                      # 合并master分支
git push -u origin master             # 上传代码

The above is the detailed content of A complete list of commonly used git commands [recommended collection]. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:learnku. If there is any infringement, please contact admin@php.cn delete
github是什么github是什么Mar 24, 2023 pm 05:46 PM

​GitHub是一个面向开源及私有软件项目的托管平台,可以让开发者们在这里托管自己的代码,并进行版本控制。GitHub主打的是开源项目与协作,通过这个平台上的开源项目,开发者们可以查看其他开发者的项目源代码,并进行交流和学习。

git中push -u是什么意思git中push -u是什么意思Jul 01, 2022 am 10:36 AM

在git中,“push -u”的意思是将本地的分支版本上传到远程合并,并且记录push到远程分支的默认值;当添加“-u”参数时,表示下次继续push的这个远端分支的时候推送命令就可以简写成“git push”。

git的pack文件有什么用git的pack文件有什么用Jun 30, 2022 pm 05:41 PM

在git中,pack文件可以有效的使用磁盘缓存,并且为常用命令读取最近引用的对象提供访问模式;git会将多个指定的对象打包成一个成为包文件(packfile)的二进制文件,用于节省空间和提高效率。

如何在GitLab上进行第一次登录并更改密码如何在GitLab上进行第一次登录并更改密码Mar 24, 2023 pm 05:46 PM

GitLab是一种基于Web的Git版本控制库管理软件,旨在帮助开发团队更好地协同工作,提高工作效率。当您第一次登录GitLab时,系统会提示您要更改初始密码以确保账户安全。本文将为大家介绍如何在GitLab上进行第一次登录并更改密码。

git中pull失败了怎么办git中pull失败了怎么办Jun 30, 2022 pm 04:47 PM

git中pull失败的解决方法:1、利用“git reset --hard”强制覆盖掉自己的本地修改;2、利用“git stash”推送一个新的储藏,拉取之后利用“git stash pop”将修改保存到暂存区;3、若依然出现问题,则将文件保存到暂存区并提交注释即可。

git分支能改名字吗git分支能改名字吗Jun 16, 2022 pm 05:55 PM

git分支能改名字。改名方法:1、利用git中的branch命令修改本地分支的名称,语法为“git branch -m 旧名字 新名字”;2、利用“git push origin 新名字”命令,在删除远程分支之后将改名后的本地分支推送到远程;3、利用IDEA直接操作修改分支名称即可。

用三行代码使你的git提交记录变干净用三行代码使你的git提交记录变干净Feb 28, 2023 pm 04:19 PM

本篇文章给大家带来了关于git的相关知识,其中主要跟大家聊一聊怎么让你的git记录保持整洁,感兴趣的朋友下面一起来看一下吧,希望对大家有帮助。

git怎么删除某个分支git怎么删除某个分支Jun 24, 2022 am 11:11 AM

git删除某个分支的方法:1、利用“git branch --delete dev”命令删除本地分支;2、利用“git push origin --delete branch”命令删除远程分支;3、利用“git branch --delete --remotes”命令删除追踪分支。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool