April
19th,
2019
GIT的分支是众多版本管理软件中最好用的,没有之一.在创建,同步,合并过程中都显示出其设计的优越性.这里主要记录一些和分支相关的操作.
创建分支
git checkout -b branch-name分支改名
git branch -m oldName newName删除分支
删除本地分支
git branch -d branch-name删除远程分支
git push origin :remote_branch_name查看分支追踪情况
git remote show origin本地同步远端已被删除的分支
git remote prune origin将本地分支推到远程如果不存在就创建
git push origin local_branch_name:remote_branch_name合并Commit
- 从HEAD版本开始往过去数三个版本
git rebase -i HEAD~3- 指定要合并之前的版本号
git rebase -i commitId查看某个 Commit 所属的分支
git branch --contains commitId对比两个分支的差异
显示两个分支的差异文件列表
git diff branch1 branch2 --stat显示指定文件的详细差异
git diff branch1 branch2 filePath显示所有文件的详细差异
git diff branch1 branch2合并分支
git checkout branch-name
git pull
git merge origin/other-branch-name合并分支但不形成 merge commit
git fetch origin
git checkout target-branch-name
git merge --no-commit source-branch-name从其它分支抓取 Commit
git cherry-pick commitId
git cherry-pick commitId0 .. commitIdN 将指定文件夹换成指定分支中的版本
撤消分支合并
只查看指定分支的 commit 记录
git log --oneline --walk-reflogs branch-nameTag 操作
添加 TAG
git tag -a v1.0.1.1 commit-id删除 TAG
git tag -d v1.0.1.1删除远程 TAG
git push origin :refs/tags/v1.0.1.1推送 TAG
git push origin v1.0.1.1
git push origin --tagsstash 相关
把工作区中的修改藏起来
git stash push -m "message"
git stash save
git stash store查看 stash 保存的内容
git stash list
git stash show -p
git stash show -p stash@{1}把 stash 中的内容还原出来
git stash pop
git stash apply把 stash 中的内容清除掉
git stash clear
git stash dropgit 使用指定的密钥
git config core.sshCommand "ssh -i ~/.ssh/id_rsa_example -F /dev/null"添加多个 tracked repositories
添加
git remote add name git-url删除
git remote remove name改名
git remote rename <old> <new>裸仓库
git clone --bare git-url更新祼仓库
git fetch origin +refs/heads/*:refs/heads/* --prune镜像推送
git push --mirror <remote-repo>SubModule 使用
1. 添加
git submodule add git-url path2. 使用
在已经添加了子模块的仓库拉取之后需要用下面的方式将子模块中的代码同步到本地.
git submodule init
git submodule update或者:
git submodule update --init --recursive3. 更新
子模块的维护者提交了更新以后,使用子模块的项目必须手动更新才能包含最新提交.
进入到子模块目录下执行 git pull 更新, 然后在项目目录中 git add 提交即可.
统一更新全部子模块
git submodule foreach git pull引用的子模块可以锚定在某一个 commit 或者某一个特定的分支上,使用维护起来非常方便.
4. 删除子模块
这个操作不多见,但是遇到了就挺烧脑的.
- 删除子模块目录
rm -rf 子模块目录- 打开 .gitmodules 删除相关条目
- 打开 .git/config 删除配置中子模块相关条目
- 删除 __.git/module/__中的对应目录. 每一个子模块在该目录下会有一个对应的目录 只删除对应的子模块目录即可
rm -rf .git/module/... - 删除缓存区的子模块相关内容
git rm --cached 子模块名- 完成删除后提交到仓库即可.
您的打赏是对我最大的鼓励!
支付宝打赏
微信打赏