git创建分支,提交分支

查看分支:

git branch

创建本地分支并切换到新创建的分支

git checkout -b dev

创建分支:

git branch dev

切换分支

git checkout dev

提交到分支

git push origin dev

彻底清除某个不应该上传的超大文件

git filter-branch –tree-filter ‘rm -f 文件名’ HEAD  或者 git filter-branch –tree-filter “find * -type f -name ‘word2vec_baike*’ -delete” HEAD

 

清理大文件,彻底删除(实际操作,同事上传了超大文件后处理办法)

参考文章https://blog.csdn.net/qq997843911/article/details/88979051

对于不清楚哪个文件超大,可以先找到大文件

找到占用空间最多的5个文件
git rev-list --objects --all | grep "$(git verify-pack -v .git/objects/pack/*.idx | sort -k 3 -n | tail -5 | awk '{print$1}')"

找到id对应的文件名

git rev-list –objects –all | grep 890d280cc94ebfb0ad7cf66b02b6d21a7e5e3ef8

删除文件的历史记录(验证确实有效)

git filter-branch –force –index-filter ‘git rm –cached –ignore-unmatch –ignore-unmatch your_file’ –prune-empty –tag-name-filter cat — –all

可能会报错:Cannot rewrite branches: You have unstaged changes

解决方案:执行git stash即可解决。

提交

git push –force –all

清除本地缓存

rm -Rf .git/refs/original

rm -Rf .git/logs/

git gc

git prune

 

 

以下是另外一种方法:尝试多次未删除

用 git filter-branch -f –index-filter “git rm -rf –cached –ignore-unmatch  上面查找的文件名” — –all

挨个执行大文件删除,后续操作

rm -rf .git/refs/original/

git reflog expire –expire=now –all

git fsck –full –unreachable

git repack -A -d

git gc –aggressive –prune=now

git push –force [remote] master

 

 

git添加子模块

git submodule add  https://github.com/xxxx local_dirname 
会产生一个 .gitmodules 的文件
例如:
[submodule "DbConnector"]
	path = DbConnector
	url = https://github.com/chaconinc/DbConnector

克隆含有子模块的项目:
git clone 后子模块内容为空,需要运行两个命令:git submodule init 用来初始化本地配置文件,而 git submodule update 则从该项目中抓取所有数据并检出父项目中列出的合适的提交。
更简单的办法是:
给 git clone 命令传递 --recurse-submodules 选项,它就会自动初始化并更新仓库中的每一个子模块, 包括可能存在的嵌套子模块

如果你已经克隆了项目但忘记了 --recurse-submodules,那么可以运行 git submodule update --init 将 git submodule init 和 git submodule update 合并成一步。如果还要初始化、抓取并检出任何嵌套的子模块, 请使用简明的 git submodule update --init --recursive。

克隆的时候直接加上 --recursive

git 合并分支的某个文件到主干

 git checkout –patch 分支名称  要合并的文件路径

例如:  git checkout –patch dev https://w.src.corp.qihoo.net/cloudsafeoffline/tech_assessment/api_gateway_document/tree/master/apidoc/innerapis

然后再执行:

git add -A 文件路径
git commit -m ‘注释’
git push
如果不想合并只是测试 一定要回滚回来
git reset –hard origin/master 到上一个版本

You May Also Like

About the Author: daidai5771

发表评论

电子邮件地址不会被公开。 必填项已用*标注