1. 下载代码
git clone git库
2. 查看分支
查看当前分支:git branch
查看所有分支(包括本地和远端):git branch -a
查看所有远端分支:git branch -r
3. 创建新分支并切换
git checkout -b new-branch origin/branch
4. 查看提交日志
git log
5. 切换分支
git checkout bake
6. 查看提交状态
git status
7. 添加修改文件
git add file
8. 提交修改
git commit -m comment
9. 合并分支
git merge branch
10. push到主分支
git push origin master
11. 查看文件改动状态
git status
12. 切换回未改动原分支
git checkout .
13. 配置git忽略文件
vim .gitignore
*.iml
.idea/
*target/
14. 撤销commit
1)先保存本次commit和上一次commit的diff
git diff now_commit_id last_commit_id > my_patch.diff
2) hard reset,撤回本次commit,修改代码丢弃
git reset --hard last_commit_id
3) 更新本地代码
git pull
4) apply diff,将修改代码apply到代码库
git apply mypatch.diff
5) 重新commit & push
15. 删除某个分支
git branch -D branch_name
16. 切换某个tag
git tag 查看所有tag
git checkout -b branch_name tag_name
17. github fork后同步master分支
git remote -v
git remote add upstream git@github.com:xxx/xxx.git
git fetch upstream
git merge upstream/master
git push -f
18. 开源分支合入内部git项目新分支
git clone git@gitlab.com:xxx/xxx.git
cd apsara-spark/
git remote -v
git remote add upstream git@github.com:apache/spark.git
git remote -v
git fetch upstream
git branch branch-2.4 v2.4.2
git status
git branch -a
git checkout branch-2.4
git push origin branch-2.4
git branch