GIT归纳整理 1. 将repo_a的分支提交到repo_b分支 2. 删除远程分支 3. 修改gitlab.com Default Branch 4. git format-patch和git am 5. tag相关 6. 本地目录提交远程 7. 子模块submodule 8. patch -p1 < ../linux-4.9.56.patch 9. git archive只取git中单个文件 10. 删除存在本地而远程不存在的分支 0. 其他常用

repo_a:表示原始git库地址;repo_b:表示新增的git库地址。

git remote add new_remote repo_b:new_remote 是repo_b在repo_a中的别名。为本地repo_a新建remote名称,也即另一个repo。

在.git/config中就会新增一个remote:

[remote "new_remote"]
    url = http://.../linux.git
    fetch = +refs/heads/*:refs/remotes/new_remote/*

git push new_remote master:是将本地的repo_a master分支upload到repo_b master分支。

git push new_remote fpga:master:是将本地的repo_a fpga分支upload到repo_b master分支。

2. 删除远程分支

git push to_origin --delete master:删除to_origin指向的repo的master分支。

git push origin HEAD:origin/update_csky_kernel

将repo_b分支branch_a cherrypick到分支branch_b

3. 修改gitlab.com Default Branch

Setting->Edit Porject->Default Branch下拉列表中选择想要设置的Branch名称。

4. git format-patch和git am

git format-patch commit-id:从commit-id开始(不包括),生成相应的patch。

git am *.patch:将*.patch补丁。

5. tag相关

新建删除tag:

git tag -a v0.0.0 -m "First demo version."---------新建v0.0.0的tag,并且注释。
git tag--------------------------------------------显示新增的tag。
git push origin --tags-----------------------------将tag上传到服务器。
git show v0.0.0------------------------------------显示tag详情。
git tag -d v0.0.0----------------------------------删除tag。

6. 本地目录提交远程

将本地代码上传到git服务器进行管理,如下:

git init----------------------------------------------------在当前目录创建git仓库。
git add .---------------------------------------------------将所有文件加入到仓库。
git commit--------------------------------------------------增加commit message。
git remote add origin http://.../busybox.git----------------增加remote git服务器。
git push -u origin master-----------------------------------提交commit到远程服务器。

7. 子模块submodule

当项目越来越庞大之后,不可避免需要拆分成多个子模块。

如果希望各个子模块独立版本管理,就需要git submodule功能。

7.1 引入子模块,并提交子模块信息

git submodule add http://../submodule.git submodule_folder---------------其中submodule.git是待引入子模块的git,submodule_folder是当前project下面一个目录。
git status---------------------------------------------------------------可以看出会增加一个.gitmodules文件以及submodule_folder目录,这两个都需要提交。
git diff
git add .----------------------------------------------------------------add两个文件.gitmodule和submodule_folder。
git commit -m "add submodule"
git push origin master---------------------------------------------------提交到远程。

7.2 下载子模块

在clone project的时候,带submodule的时需要附上--recursive。

就可以将submodule一并更新。

git clone --recursive http://.../project.git

如果在clone的时候没有附带--recursive,可以在clone之后如下操作。

在project目录,同样可以更新submodule:

git submodule init
git submodule update

7.3 更新子模块commit id

当需要跟随submodule更新时,只需要更新submodule指向的commit id。

git checkout master-----------------进入submodule目录,切换到master分支。
git pull----------------------------更新到最新的submodule。

然后在上一层目录中git status可以看到,显示对应submodule目录的仅更新了commit id。

GIT归纳整理
1. 将repo_a的分支提交到repo_b分支
2. 删除远程分支
3. 修改gitlab.com Default Branch
4. git format-patch和git am
5. tag相关
6. 本地目录提交远程
7. 子模块submodule
8. patch -p1 < ../linux-4.9.56.patch
9. git archive只取git中单个文件
10. 删除存在本地而远程不存在的分支
0. 其他常用

然后执行git add pre_dl、git commit、git push即可更新。

参考文档:《Git Submodule管理项目子模块

8. patch -p1 < ../linux-4.9.56.patch

9. git archive只取git中单个文件

git archive --remote=/path/to/repo HEAD:/path/to/file file | tar -x

10. 删除存在本地而远程不存在的分支

git remote prune origin

           Deletes all stale remote-tracking branches under <name>. These stale branches have already been
           removed from the remote repository referenced by <name>, but are still locally available in
           "remotes/<name>".

           With --dry-run option, report what branches will be pruned, but do not actually prune them.

0. 其他常用

git config --global credential.helper store:永久记住密码。

git config –global credential.helper cache:默认记住15分钟。

git config credential.helper ‘cache –timeout=3600’:下面是自定义配置记住1小时。