git官网: https://git-scm.com/
常用命令
- clone :-----git clone http://127.0.0.1/surliya/gittest.git
- add: 注意不要什么都提交.gitignore
git config --global user.name "_surliya_"
git config --global user.email "_surliya@qq.com_"
cd gittest
git init
git remote add origin http://127.0.0.1/surliya/gittest.git
git add .
git commit -m"init"
git push -u origin master - commit: 规范Message ------commit -m"update"
- push : ------ git push -u origin master
- pull(作用是:取回远程主机某个分支的更新,再与本地的指定分支合并)
---------git pull [远程主机名] <远程分支名>:<本地分支名>
git pull origin next:master
git pull origin next(远程分支next要与当前分支合并)
==>git fetch origin next:master(获取)
-> git diff next(查看)
-> git merge next(合并)
(更安全,可以在merge前,查看跟新情况,再决定是否合并) - branch(git clone 时,本地master分支自动"追踪"origin/master分支)
git branch --set-upstream master origin/next(手动建立追踪关系) - checkout(开启分支并切换): git fetch origin 分支,git checkout -b 分支 origin/分支 /* git checkout origin/分支 */
git checkout [-b] testbranch ==> git branch testbranch
git add -A(提交修改到暂存区)
git commit -m “testbranch”(带注释提交)
git push origin testbranch(发布到gitlab上)
git checkout master (切换到master分支)
//git checkout master -> git pull origin master -> git merge dev
git rm -r --cached . // 清除本地缓存 - reset(文件从暂存区回退到工作区):
git reset HEAD readme.txt(回退文件)
git reset HEAD^(回退上个版本)
git commit --amend(追加提交)
git reset --help (查看帮助) - 冲突处理: 如何发现冲突; git merge testbranch (合并时发现冲突)
如何看冲突文件; git status -> git diff readme.txt
如何处理冲突文件; git add readme.txt -> git status -> git commit -m"update" - 将依赖加入本地 maven 库(以sapjco3为例)
mvn install:install-file -DgroupId=org.hibersap -DartifactId=sapjco3 -Dversion=3.0 -Dpackaging=jar -Dfile=E:/sapjco3/sapjco3.jar - git 合并本地两个分支
常常会遇到提pr之后,迟迟没有被审阅合并,又需要集成测试的情况,这时候就需要在本地将几个分支合并到一个临时分支tmp
方法1:git merge br1 br2
方法2:git rebase br1 br2 - git pull 撤销误操作: https://blog.csdn.net/code_segment/article/details/78597441
-
git cherry-pick 获取某分支的单笔提交: https://git-scm.com/docs/git-cherry-pick, https://blog.csdn.net/fightfightfight/article/details/81039050
其它总结
- 协议: https://git-scm.com/book/zh/v2/%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%B8%8A%E7%9A%84-Git-%E5%8D%8F%E8%AE%AE
- Git 提示fatal: remote origin already exists 错误解决办法: https://blog.csdn.net/top_code/article/details/50381432
- gitLab本地推送到远程仓库的命令: https://www.cnblogs.com/caiyineng/p/6636693.html
- git 文件添加、变更的提交: https://blog.csdn.net/dazhi_100/article/details/38851733
- 解决冲突:
- https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/001375840202368c74be33fbd884e71b570f2cc3c0d1dcf000 ;
- https://www.cnblogs.com/xiaoerlang/p/3810206.html ;
- https://blog.csdn.net/zwl18210851801/article/details/79106448
- web hook设置: https://blog.csdn.net/weiguang1017/article/details/78594507
- Access denied: https://blog.csdn.net/xiatianyangwang/article/details/78652313
- “Please make sure you have the correct access rights and the repository exists.”问题: https://blog.csdn.net/jingtingfengguo/article/details/51892864
- ssh与https互换: https://blog.csdn.net/yym836659673/article/details/77504430
- git 将项目迁移到另一个仓库: https://blog.csdn.net/zzzgd_666/article/details/81252470
- git忽略规则以及.gitignore文件不生效解决办法: https://www.jianshu.com/p/60281010a215
- git放弃本地修改: https://www.cnblogs.com/qufanblog/p/7606105.html