基础操作
bash
# 添加文件到暂存区
git add <filename> # 添加特定文件
$ git add 3.txt
git add . # 添加所有文件
# 提交更改
git commit -m "提交信息"
$ git commit -m "修改2.txt"
# 查看远程仓库
git remote -v
$ git remote -v
origin https://gitee.com/shenpengcheng030415/git01.git (fetch)
origin https://gitee.com/shenpengcheng030415/git01.git (push)
# 添加远程仓库
git remote add origin <url>
$ git remote add origin https://gitee.com/shenpengcheng030415/git01.git
# 推送到远程仓库
git push origin <branch_name>
$ git push origin master
# 从远程拉取
git pull origin <branch_name>
$ git pull origin master
分支
bash
# 查看分支
git branch # 本地分支
$ git branch
* master
git branch -a # 所有分支(包括远程)
$ git branch -a
* master
remotes/origin/master
# 创建分支
git branch <branch_name>
$ git branch b1
# 切换分支
git checkout <branch_name>
$ git checkout b1
Switched to branch 'b1'
git switch <branch_name> # 新版本推荐
$ git switch master
Switched to branch 'master'
# 创建并切换分支
git checkout -b <branch_name> <tag_name>
git checkout -b fix-v1.0 v1.0
# 会创建一个名为 fix-v1.0 的新分支,且该分支的初始状态完全等同于 v1.0 标签对应的提交(包含当时的所有文件和代码)。后续在这个分支上的修改,会基于 v1.0 的状态进行,不会影响原标签或其他分支。
git switch -c <branch_name>
# 合并分支 (是将指定分支的代码合并到当前分支)
git merge <branch_name>
$ git merge b1
# 删除分支
git branch -d <branch_name>
$ git branch -d b2