What is Git?
Git is a distributed version control system open source, for quick and efficient handling of any small or large projects.
Let's talk about Git common operations
git config common configuration
-
Configuring the mailbox and username
全局配置 git config --global user.name "your name" git config --global user.email "[email protected]" 单个项目配置(先进入项目的根目录,带有.git隐藏文件的目录) git config user.name "your name" git config user.email "[email protected]" 对单个项目进行配置可覆盖全局配置
-
Configuration command aliases
比如给 git status 设置别名 st: git config --global alias.st status
-
View existing configuration information
git config --list 或者 git config -l
Git repository creation
Git using git init command to initialize a Git repository, Git commands require a lot of running in the Git repository, so git init is the first to use Git commands.
In the execution is complete git init command, Git repository will generate a .git directory that contains all the metadata resources, and other project directory remains unchanged.
Using the current directory as the Git repository, we need to initialize it.
git init
该命令执行完后会在当前目录生成一个 .git 目录。
We use the specified directory as the Git repository.
git init projectPath
After initialization, will appear in a directory called .git directory under projectPath, Git all required data and resources are stored in this directory.
Cloning Warehouse Code
Cloning code to the current folder
git clone 仓库地址
If we need to clone to a specific directory, you can use the following command format:
git clone 仓库地址 目标文件夹
Submit trilogy
git add .
git commit -m "message"
git pull
git push
git add workspaces to submit changes to the temporary storage area;
git commit -m "message" to submit to the local staging area warehouse;
remember to commit after completing git pull out the latest update remote repository to local codes;
git push commit the local modification to a remote repository at last ensure there is no conflict without being given situation;
Common Commands
git status 查看当前状态
git add <filename> 提交文件到暂存区
git add . 提交所有工作区改动到暂存区
git log 查看提交记录
git log --graph 查看分支图合并
git reflog 查看近期所有操作提交记录
git branch -l 查看本地仓库分支
git branch -al 查看所有分支(包含本地分支和远程分支)
git checkout [分支名] 切换分支
git checkout -b [分支名] [远程分支] 基于某个远程分支新建分支并切换到该分支
git branch -d [分支名] 删除某分支
git merge [分支名] 分支进行融合
git remote 查看远程库信息 -v 详细信息
git tag 查看本地仓库所有标签
git tag <name> <commitId> 默认HEAD打一个标签 可指定特定commitId -m '为标签添加注释'
git tag -d <tagName> 删除某个标签
git push -d origin <tagName> 删除远程标签
git push --tags 将本地标签一次性推送到远程
git push origin <tagName> 推送指定标签到远程