Git备忘手册

1.更新远程分支

git remote update origin -p

git push origin –delete xxx

2.清除.idea的git缓存

git rm -r –cached .idea

3.Git Flow代码示例

a. 创建develop分支

1
2
git branch develop
git push -u origin develop

b. 开始新Feature开发

1
2
3
4
5
6
7
8
git checkout -b some-feature develop
# Optionally, push branch to origin:
git push -u origin some-feature

# 做一些改动
git status
git add some-file
git commit

c. 完成Feature

1
2
3
4
5
6
7
8
9
git pull origin develop
git checkout develop
git merge --no-ff some-feature
git push origin develop

git branch -d some-feature

# If you pushed branch to origin:
git push origin --delete some-feature

d. 开始Relase

1
2
3
4
git checkout -b release-0.1.0 develop

# Optional: Bump version number, commit
# Prepare release, commit

e. 完成Release

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
git checkout master
git merge --no-ff release-0.1.0
git push

git checkout develop
git merge --no-ff release-0.1.0
git push

git branch -d release-0.1.0

# If you pushed branch to origin:
git push origin --delete release-0.1.0


git tag -a v0.1.0 master
git push --tags

f. 开始Hotfix

1
git checkout -b hotfix-0.1.1 master

g. 完成Hotfix

1
2
3
4
5
6
7
8
9
10
11
12
git checkout master
git merge --no-ff hotfix-0.1.1
git push

git checkout develop
git merge --no-ff hotfix-0.1.1
git push

git branch -d hotfix-0.1.1

git tag -a v0.1.1 master
git push --tags

4.Git 打包commit内容

1.从指定位置之后开始打包

1
2
3
4
# git bundle create <打包的文件名称> <分支名> <从指定位置之后开始打包>

例如:
# git bundle create 0208commits.bundle feature/grid ^837ef2a

2.验证是否有共同祖先

1
2
3
4
# git bundle verify 0208commits.bundle

//检查可以导入哪些分支
# git bundle list-heads 0208commits.bundle

3.从包中导入提交

1
# git pull 0208commits.bundle feature/grid:feature/grid

5.Git 导出diff

1.打包diff内容

1
# git diff HEAD > feature_a.patch

2.应用diff

1
2
3
# git apply --check feature_a.patch

# git apply --whitespace=warn feature_a.patch

3.撤回刚才打上的那个patch

1
# git apply -R feature_a.patch