Skip to content

layout: post title: "git" subtitle: "git" date: 2019-05-30 11:27:25 author: "none" header-img: "img/posts/default_post.jpg" catalog: true tags: - tag


远程分支

递归clone子仓库源码

git clone --recurse-submodules

拉取远程分支并创建本地分支 git checkout -b <本地分支名> origin/<远程分支名>

将文件移除add git reset git reset HEAD

向远程分支提交代码 git push origin :

本地分支与远程分支不同名, 设置上游远程分支

git branch --set-upstream-to=origin/<remote_branch>  <local_branch>

git clone 某个目录

git init <repo>
cd <repo>
git remote add origin <url>
git config core.sparsecheckout true
echo "<目录/目录>" >> .git/info/sparse-checkout
git pull --depth=1 origin master

远程仓库

# 查询远程仓库url
git remote -v

# 修改远程仓库
git remote set-url origin <url ssh or http>

对比分支

git diff branch1 branch2 --stat   //显示出所有有差异的文件列表
git diff branch1 branch2 文件名(带路径)   //显示指定文件的详细差异
git diff branch1 branch2                   //显示出所有有差异的文件的详细差异

合并分支

例如将branch_b 合并到branch_a上:

方法一: git merge方式

git checkout branch_a
git merge branch_b

# 合并远程分支到当前分支
git pull origin <remote-branch>

# 合并远程分支到本地指定分支
git pull origin <remote-branch>:<local-branch>

方法二: git checkout方式, 可以指定覆盖某些文件 或者使用checkout方式合并

git checkout branch_a
git checkout branch_b <path>

提交代码

# 查看更改状态
git status

# 提交所有修改
git add -A

# Changes to be committed:
# Untracked files:
# 仅提交Changes to be committed:状态的文件
git add -u

清理

# 清理 untracked files, -n表示模拟运行
git clean -fn