常用的git指令
1.初始化本地仓库
git init : 在当前目录创建空的git仓库
git init [project-name] : 新建目录并初始化仓库
2.克隆远程仓库
git clone [url]: 下载远程仓库到本地(含完整的提交历史)
3.下拉远程仓库的代码
git pull
4.关于branch
----------- 查看分支 ------- # 查看本地分支 git branch # 查看远程分支 git branch -r # 查看本地和远程分支 git branch -a ------------创建分支------------ # 创建分支 git branch <branch_name> # 创建新分支并且切换到该分支 git checkout -b <branch_name> -------------重命名分支-------------------- # 重命名分支 git branch -m 旧分支 新分支 --------------切换分支------------------ # 切换到指定分支 git checkout <branch_name> # 指定提交切换分支 git checkout <branch_name> <commit_hash>
5.合并分支
-------------1.切换到目标分支(想要合并到哪个分支)---------------- git checkout <branch_name> # 更常用的方式 git switch <branch_name> -------------2.执行合并---------------------- # 将source_branch的更改合并到当前分支 git merge <source_branch> ------------3.解决冲突(有冲突的话)------------- git add <conflicted_file> git commit
6.提交
--------------提交---------------- # 暂存文件 git add <文件名> # 暂存所有更改 git add . # 提交到本地缓存 git commit -m "提交内容"
# 在提交代码commit时,加上参数 --no-verify, 可以忽略pre-commit代码校验的钩子 ,绕过eslint的检查了。
git commit -m "提交备注" --no-verify
# 推送到远程仓库
git push