git相关 - xiaojiandong/blogAndResourceCollect GitHub Wiki

如何在本地对github网站的仓库进行操作:

   /*
   1. git clone 'https://github.com/xiaojiandong/AngularJsNote.git' (clone到本地磁盘)
   2. 在本地磁盘的文件夹中,对本地的 AngularJsNote 执行 CRUD操作
   3. git status (命令行输出操作的结果)
   4. git add .
      git add --all (提交所有文件)
   5. git commit -am "刚才你执行了某个增/删/改操作" 
   // (直接推送到远程的AngularJsNote仓库中了,需要输入github网站的username,password)
   6. git push origin master 
   7. 在github官网上,刷新页面
   8. git reflog (查看历史版本号)
   9. git reset --hard d9d3098 (回滚到之前的 d9d3098 这个版本)
   10. git config --global credential.helper store (不需要每次输入用户名/密码)
   11. git stash (存储当前的修改保留在本地,切换分支)
   12. git update-index --assume-unchanged  newfortune-yx-web/src/main/webapp/js/common/config_server.js
       (忽略某个文件,不提交他,只保留在本地)
   13. git checkout config.js // 将远程的文件覆盖掉本地文件
       git pull
       git merge dev_d
       git update-index --assume-unchanged  newfortune-yx-web/src/main/webapp/js/common/config_server.js
       git push original master
   14. git remote set-url origin http://172.18.9.155:3000/xcf/newfortune.git (覆盖掉原有的远程地址) 
   15. git update-index --no-assume-unchanged  newfortune-yx-web/src/main/webapp/js/common/activeList.css
       (去掉该文件的打勾状态,允许其被修改并提交)
   */

操作流程截图:

images images

微信授权登录:

//去授权
        $scope.goauth = function(){
            var callbackurl = encodeURIComponent(window.location.href.replace('code',''));
            window.location.href = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx207d11f2e5da4961&redirect_uri='+callbackurl+'&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect';
        };

GIT版本回滚

 1. 记住你上次提交的版本号,作为回滚依据
 2. 在Git Bash 中输入: git reset --hard commit_version (此命令可以回到过去或未来的版本号)
 3. 成功回滚到过去提交的版本号
 4. git log :查看历史提交的版本
 5. git reflog:查看未来版本
  1. 廖雪峰git讲解链接

image image

GIT删除/切换/拉取/推送分支:

 1. git push origin local_name:master_name // local_name一般和master_name名字一样
 2. git branch -D activity_pop_king_dzf   //  强制删除了 activity_pop_king_dzf 分支 
 3. git checkout -b activity_pop_king_dzf   // 新创建了 activity_pop_king_dzf 分支,并切换到了该分支
 4. git checkout -b activity_pop_king --track origin/activity_pop_king // 拉取远程的activity_pop_king分支到本地
 5. git branch -vv  // 显示本地分支和远程分支的对应
 6. git merge a_branch // 将a_branch分支合并到当前分支
 7. git push origin dzf_act_name //推送到远程的dzf_act_name分支
 8. git branch -r -d origin/origin-branch-name
    git push origin :origin-branch-name // 删除远程分支
 9. git push origin dzf_act:dzf_act //推送本地分支dzf_act到远程新的分支dzf_act
 10. git push origin dzf_act // 本地修改好后,推送到远程的dzf_act
 11. git pull 与 git fetch的区别
     git pull // 获取远程最新版本到本地,并merge
     git fetch // 获取远程最新版本到本地,不会merge

Git 安装时,配置鼠标右键出现Git Bash

image

遇到本地被覆盖的错误

$ git pull origin master // 1. 拉取远程代码报错
From http://172.11.11.125:3000/xcf/newfortune
 * branch            master     -> FETCH_HEAD
Updating 795e383..412cfdb
error: Your local changes to the following files would be overwritten by merge:
        newfortune-yx-web/src/main/webapp/WEB-INF/view/myCreate.html
        newfortune-yx-web/src/main/webapp/js/common/config.js
Please, commit your changes or stash them before you can merge.
Aborting
$ git reset --hard // 2. 解决方法(回滚)
$ git pull origin master // 3. 再次拉取,并覆盖掉本地代码