打开git的 bash:

    》git  version   //查看客户端版本

   》git update     //会提示升级   git update-git-for-windows //新版本采用这种升级方式

     当提示有:rate limit rules.问题时,使用

     》curl -I https://api.github.com/users/octocat

    然后重新  git  update。

》git config --global user.name '用户名'

》git config --global user.email '邮箱'

》git config --global list  //查看

》git config --global credential.helper store  // 要求记录用户名和密码,这样不用每次都输入用户名和密码

》git credential-manager uninstall               // 忘记用户名和密码

 

》git config --global commit.template d:/software/git/mytemplate.txt    //创建提交模板,描述信息用#标识

》ssh-keygen -t rsa -C '邮箱'

进入git的指定目录下

 》git clone [url] -b [branch] 

 》 git clone --branch [tags标签] [git地址]   //下载tag标签

》git init  //初始化本地仓库,会在对应的文件夹下生成.git文件夹仓库地址

》git remote add orign <url>   //适合本地建立git资源,然后直接推送到远端,因远端有个初始值,本地会落后于远端因此pull完后,要rebase再提交

》git  pull        //拉取最新代码到本地

》git pull origin master

》git pull --set-upstream origin2 master // 指定默认从origin2远端地址拉取

》git commit -a    // 整合git add,git commit 只针对修改、删除的数据文件,不针对新增的数据文件,输入后会要求填写message

》git commit -m  'message信息'     // 一般提交,无需打开vim编辑器,但是需要先git add

》git commit -a  -m  'message信息'   //直接提交式,但是无法辨别本地的代码哪些应该提交,哪些不应该会一股脑提交上去

》git commit --amend  -a   'message信息'    //当我们给本地提交一版后,觉得不是很满意,想要在这一版上修改,但是不想有新的版本,则可以通过此命令。

》git commit --amend --no-edit

》git rebase -i [startpoint] [endpoint]   // 将startpoint 和 endpoint的commit内容变更合并

  • pick:保留该commit(缩写:p)
  • reword:保留该commit,但我需要修改该commit的注释(缩写:r)
  • edit:保留该commit, 但我要停下来修改该提交(不仅仅修改注释)(缩写:e)
  • squash:将该commit和前一个commit合并(缩写:s)
  • fixup:将该commit和前一个commit合并,但我不要保留该提交的注释信息(缩写:f)
  • exec:执行shell命令(缩写:x)
  • drop:我要丢弃该commit(缩写:d)

 

》git push   // 提交

》git push origin [branchname]

》git push -u origin master   //-u将当前的提交分支作为默认分支,下次直接git push即可。 

》git push origin head:refs/for/[branchname]  //gerrit提交方式

》git log   //查看本地提交内容 

》git log -p [fileName]    // 查看一个文件的历史修改记录,包括变动点

 

--------Tag  start----------

》git tag -l    //查看tag列表

》git tag -n  // 查看tag的相关信息

》git tag -a [tag名] -m '[message]'    // 新创建tag,tag要在对应的分支下创建

》git show [tag名]                            // 查看创建tag的信息

》git show [commitId]                     // 查看已提交信息的变更

》git push origin [tag名]                  // 提交tag

》git tag -d [tag名]                          //删除本地tag

》git push origin :refs/tags/[tag名]  //删除远端tag,注意要有 :

》git push origin --delete  [tag名]    //删除远端tag,快速删除,这种注意branch相同的话,用第一种删除

 

参考Tag文章: https://git-scm.com/book/zh/v2/Git-%E5%9F%BA%E7%A1%80-%E6%89%93%E6%A0%87%E7%AD%BE

--------Tag  end----------

 

-------REMOTE  start -----

git remote -vv      //查看远端仓库

git remote  add   myorigin ssh://****.git         //增加新的远端仓库

git push myorigin    //推送本地代码到新的远端

git pull myorigin     //从新的远端仓库拉取代码

------REMOTE    end------

 

# 分支

》git branch  //查看本地分支,带*的为当前分支

》git branch [branchname]   //创建本地分支版本

》git branch -D [branchname]  //删除本地分支版本

》git push origin --delete dev  // 删除远端

》git branch -a  //查看远端分支版本

》git branch -vv //查看本地和远端的对应关系

》git remote -v  //远端地址

》git checkout [branchname]  //切换本地分支

》git checkout --track origin/branch_name  //创建本地并关联远端

》git checkout -- [fileName]    //git checkout -- pom.xml 就如同idea中的rollback类似git restore命令

》git checkout -b [branch_name]   origin/branch_name   //创建本地并关联远端

》 git push --set-upstream origin branch_name                                    //本地存在,远端不存在

git branch --set-upstream-to origin/分支名  或者 git branch -u origin/分支名   //本地当前分支关联远端分支

》git merge master  //将本地master分支的内容merge到当前版本

》git merge --squash [branch]   //merge并合并分支的所有提交为一条记录,注意此时会谁合并作者记录谁

》git merge --rebase [branch]   // 此时需要手动的调整rebase记录,比如有1,2,3,4 提交,2,3为对1提交的fix,则将文本的pick变更为fixup,然后提交,这样在主分支上看到的就是1,4

》git merge origin/master  // 从远端获取合并

》git merge origin/master  -- --allow-unrelated-histories // 从远端获取合并(针对此异常:fatal: refusing to merge unrelated histories)

git rebase --abort

》git merge [branch] --no-commit   //不提交式合并,在用gerrit时,一般用这个,不提交代码可以通过git merge --continue来处理merge提交。如果提交则必须再次提交作为merge冲突处理。

》 git merge origin/master  //将远端master分支merge到本地  (这种注意权限)

》git status    // 查看未提交信息数据

》git add   [file]    // 提交文件

》git  add  .        //提交当前目录下的所有文件

》git restore [filepath]   //复原在本地区的文件workspace中,注意是没有add的文件 也可使用 git checkout -- [filepath]

》git rm -r --cached [filepath]     //cached的内容移除

》git clean -f -d   //移除未在缓存区的文件(-f)和目录(-d) 

》git restore --staged  //将暂存区文件撤出来,但是修改的文件不撤回。

》git add  [path/**]   采用通配符方式添加

》git diff   [filepath]    //查看版本修改对比

》git checkout    [branchName]     //切换分支版本

---远端下载和本地冲突

》git add .  //先将自己的保存

》git stash save 'message'// 本地影子保存

》git stash list //查看本地保存

》git stash show //查看本地保存

》git pull //从远端获取

》git stash apply //调出自己的影子保存

然后处理merge,

》git stage clear //处理完后,清除stage

》git merge --continue        //git merge完后,继续

》git merge  --abort            //放弃merge

》git archive -v adf38df5007c3f7cf0fa369d874927def0ae9586 --format zip --output "C:\Users\denny\Desktop\temp\v1.zip"    //将代码的tag这个版本导出

 

克隆地址 :

git  clone  [url]

 》git clone [url] -b [branch]

关闭ssl验证:

git config --global http.sslVerify false

 

git revert [commandId]    //将当前版本的内容撤掉重新做,内容会回滚,但是别的版本不受影响,例如:A·B·C 3次提交, revert B的话,B的内容会全部撤销移除,但是A,C的内容还保留

git reset --soft [commandId]     //本地版本回退,仅回退版本,不回退内容。版本为要毁掉版本的上一版,也就是我们要回滚到的版本

git reset --hard [commandId]   //版本和内容都回退,版本为要毁掉版本的上一版,也就是我们要回滚到的版本

git push -f origin [branch]          //经过reset后,强制将本地代码提交,这样远端就使用自己的分支设置(一般不推荐)

git commit --m '修改某某内容'

git commit --amend --no-edit 

git commit --no-edit 

 

git reset --soft origin/master  重置commit

 

posted on 2018-08-27 16:11  zhaoqiang1980  阅读(52)  评论(0编辑  收藏  举报