zoukankan      html  css  js  c++  java
  • Git使用总结

    怎么向github account增加SSH:

    https://help.github.com/articles/checking-for-existing-ssh-keys/ 查看已经存在的ssh

    https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/ 创建一个新的ssh

    https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/#adding-your-ssh-key-to-the-ssh-agent 向github增加ssh

    正常来说,想要在本地push代码到仓库:

    http://www.cnblogs.com/dinphy/p/5618980.html 我刚刚发现这个博客有错误

    关于先commit还是先pull的问题:https://segmentfault.com/q/1010000009549291

    搜藏一个git笔记:http://blog.justwe.site/2017/05/27/git-workflow/

    总结一下先commit再pull的原因:commit是为了将你修改的东西传上去,pull是将别人更新到远程的东西同步到自己本地。pull-->commit-->push会覆盖掉自己辛苦写的东西,所以要先commit,交代一下改了什么东西。

    本地仓库第一次建立之后,如果不删除或者不重新创造,就会继续存在。所以!!

    想要上传某个文件夹的东西到新的remote 仓库里就应该先进入需要上传的文件所在文件夹,然后

    step zero :进入想要上传的文件所在文件夹,新建本地仓库

    git init

    step one : 关联github

    git remote add origin git@github.com:developerChenRui/scene_recognition

    step two : add 想要上传的文件

    git add output_graph.pb

    step three : commit

    git commit -m "init commit"

    step four : pull 一般 push之前pull一下

    git pull origin master

    step 4.5 :常常我们第一次想要上传一个文件到remote端时,我们发现本地没有readme但是remote就有readme,这时候pull,会提示错误:

    fatal: refusing to merge unrelated histories

    如果不处理,直接push,会出现:

    error: failed to push some refs to 'git@github.com:developerChenRui/OpenCVExercise'

    这时候后只要进行以下代码,readme就会被下载在本地仓库,然后一起push就好。

    git pull origin master --allow-unrelated-histories

    step five : push

    git push -u origin master

    如果想要删除仓库里的某一文件或文件夹:

    git rm -rf transfer_learning/tmp_compress/model
    
    git commit -m "Remove old model"
    
    git push -u origin master

    所以不正常的情况叫:上传的文件大于100M,超过50M给warning(不用管,可以正常上传),超过100M给error,

    错误提示是:

    remote: Resolving deltas: 100% (4/4), completed with 1 local object.
    remote: warning: File transfer_learning/tmp_compress/imagenet/inception-2015-12-05.tgz is 84.81 MB; this is larger than GitHub's recommended maximum file size of 50.00 MB
    remote: warning: File transfer_learning/tmp_compress/imagenet/classify_image_graph_def.pb is 91.24 MB; this is larger than GitHub's recommended maximum file size of 50.00 MB
    remote: warning: File transfer_learning/tmp_compress/output_graph.pb is 83.41 MB; this is larger than GitHub's recommended maximum file size of 50.00 MB
    remote: error: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.
    remote: error: Trace: df5686918af6b026bb4db840cb0fdac3
    remote: error: See http://git.io/iEPt8g for more information.
    remote: error: File transfer_learning/tmp_compress/retrain_logs/train/events.out.tfevents.1509633850.chenruideMacBook-Pro.local is 211.68 MB; this exceeds GitHub's file size limit of 100.00 MB

    方法一:FSL

    文件超过100M这时候就需要用上git lfs,详细使用见下面博客:

    http://blog.csdn.net/tyro_java/article/details/53440666

    或者看https://git-lfs.github.com官网

    但是说个异常坑的事情。。。。貌似现在不能用lfs上传到public fork。(解决办法写在最后)

    chenruideMacBook-Pro:tmp_compress chenrui$ git push -u origin master
    Git LFS: (0 of 1 files) 0 B / 83.41 MB                                         
    batch response: @developerChenRui can not upload new objects to public fork developerChenRui/scene_recognition

    方法二:删掉大文件

    如果想采用第二种方法,即删掉大文件再上传,很有可能最开始没注意这个文件超过了50M就commit了,这样就会出现一个问题:就算重新add其他文件(除去这个大文件),这个文件还是在commit里面,所以我用的方法是reset一下:

    git reset --hard b8ad1d4e71440f52fa2d44402c78f7083bc8dd85

    这样就能回到没有commit这个文件的时候,但是谨记:这样会把本地这个文件也删除掉,所以在执行这条命令时,先要把它copy一下!!

    还有一个问题是hard这串代码的后面一串怎么得来的:这个代码叫做HEAD版本的SHA,通过以下命令可以看到sha,也就是commit后面那一串:

    git log

    方法来源于这里:http://blog.csdn.net/changtianshuiyue/article/details/46672831 这里面还讲了怎么设置buffersize

    虽然给了warning因为文件超过50M,但是还是push成功的。

    chenruideMacBook-Pro:tmp_compress chenrui$ git push -u origin master
    Counting objects: 7, done.
    Delta compression using up to 4 threads.
    Compressing objects: 100% (5/5), done.
    Writing objects: 100% (7/7), 77.31 MiB | 17.05 MiB/s, done.
    Total 7 (delta 1), reused 1 (delta 0)
    remote: Resolving deltas: 100% (1/1), completed with 1 local object.
    remote: warning: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.
    remote: warning: See http://git.io/iEPt8g for more information.
    remote: warning: File transfer_learning/tmp_compress/model/output_graph.pb is 83.41 MB; this is larger than GitHub's recommended maximum file size of 50.00 MB
    To https://github.com/developerChenRui/scene_recognition
       b534e3a..fcccb5f  master -> master
    Branch master set up to track remote branch master from origin.

    其他错误合集:

    不知道当前有什么错误的时候,用一下git status看一下目前状况。

    于是会看到有两个状态

    Changes to be committed: 这是你需要commit push上传的file

    Untracked files: 这个是该目录下其他你没有add的file

    但其实状态不只两种,详细的见以下博客:

    http://phplaber.iteye.com/blog/1699926

    http://blog.csdn.net/xiao_xuwen/article/details/53420722 四种状态和索引

    https://git-scm.com/book/zh/v2/Git-基础-记录每次更新到仓库

    如果出现错误 failed to push some refs to:

    chenruideMacBook-Pro:tmp_compress chenrui$ git push origin master 
    To https://github.com/developerChenRui/scene_recognition
     ! [rejected]        master -> master (non-fast-forward)
    error: failed to push some refs to 'https://github.com/developerChenRui/scene_recognition'
    hint: Updates were rejected because the tip of your current branch is behind
    hint: its remote counterpart. Integrate the remote changes (e.g.
    hint: 'git pull ...') before pushing again.
    hint: See the 'Note about fast-forwards' in 'git push --help' for details.

    有可能是,原来仓库里面有的文件,你本地没有,所以可以用以下代码:

    git pull --rebase origin master

    相似问题博客:

    http://blog.csdn.net/u011471873/article/details/51462871

    虽然我首次上传没有设置什么用户权限什么的,也成功了,但是后面push莫名其妙的出现,permission denied的问题,解决方法是,添加key:

    具体操作:http://blog.csdn.net/luckyyulin/article/details/21090905

    出现remote连接错误连接到了另外一个仓库,需要重新连接就用:

    git remote rm origin
    git remote add origin git@github.com:developerChenRui/scene_recognition

    出现Please enter a commit message to explain why this merge is necessary.按照以下方法

    1.按键盘字母 i 进入insert模式
    
    2.修改最上面那行黄色合并信息,可以不修改
    
    3.按键盘左上角"Esc"
    
    4.输入":wq",注意是冒号+wq,按回车键即可

    分享一个神奇的bug,不可描述。。

    chenruideMacBook-Pro:tmp_compress chenrui$ git add model

    fatal: pathspec 'model' did not match any files

    chenruideMacBook-Pro:tmp_compress chenrui$ cd ..

    chenruideMacBook-Pro:transfer_learning chenrui$ git add model

    chenruideMacBook-Pro:transfer_learning chenrui$ git commit -m "model"

    [master 62c05c7] model

     3 files changed, 1204 insertions(+)

     create mode 100644 transfer_learning/model/LICENSE

     create mode 100644 transfer_learning/model/imagenet_comp_graph_label_strings.txt

     create mode 100644 transfer_learning/model/tensorflow_inception_graph.pb

    add错了我是想要add compress里的model,所以我就reset了一下,重新进入compress,就可以add model了

    chenruideMacBook-Pro:transfer_learning chenrui$ git reset --hard b8ad1d4e71440f52fa2d44402c78f7083bc8dd85

    HEAD is now at b8ad1d4 Add files via upload

    chenruideMacBook-Pro:transfer_learning chenrui$ cd tmp_compress

    chenruideMacBook-Pro:tmp_compress chenrui$ git add model

    chenruideMacBook-Pro:tmp_compress chenrui$ git commit -m "model"

    [master ec73b81] model

     2 files changed, 5 insertions(+)

     create mode 100644 transfer_learning/tmp_compress/model/output_graph.pb

     create mode 100644 transfer_learning/tmp_compress/model/output_labels.txt

    关于分支,我觉得一直没搞清楚,贴几个博客,方便遇到问题再学习:

    查看当前分支

    git branch

    https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/001375840202368c74be33fbd884e71b570f2cc3c0d1dcf000

    http://blog.csdn.net/leeagle/article/details/7818897

    http://www.cnblogs.com/wangmingshun/p/5425150.html

    关于merge

    http://blog.csdn.net/junmuzi/article/details/60781504 

    http://blog.csdn.net/byoooy/article/details/52263404

    当出现:

    fatal: remote origin already exists.

    表示已经连上了,如果不放心,也可以重新连接:

    git remote rm origin
    git remote add origin git@github.com:developerChenRui/scene_recognition

    如何跟踪或取消跟踪文件:

    http://blog.csdn.net/pengchaozhang111/article/details/51438881

    如果查看git status发现

    Your branch is ahead of 'origin/master' by 1 commit.

    而这个commit你又不想push了,或者出错无法push,想要回到与origin/brance up-to-date的状态,那就先git log查看好没有commit该文件时的SHA,reset以下,就可以了,这时候查看git status显示:

    chenruideMacBook-Pro:tmp_compress chenrui$ git reset --hard fcccb5fd1fc27143d57ad0794edc846b20156658
    HEAD is now at fcccb5f model
    Encountered 1 file(s) that should have been pointers, but weren't:
        transfer_learning/tmp_compress/model/output_graph.pb
    chenruideMacBook-Pro:tmp_compress chenrui$ git status
    On branch master
    Your branch is up-to-date with 'origin/master'.

    最后最后,慎用reset,因为本地文件也会跟着被删除,垃圾箱里都找不到!!一定要先copy一下!!!

    找了一下上传100M的解决方法:https://github.com/git-lfs/git-lfs/issues/1449

    应该就交给原仓库创建人push。只要仓库里面有了一个lfs,其他人也能正常上传了!!这绝对是个大BUG!!!!!

  • 相关阅读:
    go系列(6)- beego日志模块的使用
    shell学习(8)- ulimit调优系统参数
    新年开工
    No module named yum错误的解决办法
    如何杀死defunct进程
    图灵机器人微信自动聊天功能
    go系列(5)- beego自己写controller
    Hadoop/Spark 集群都启动了哪些 Java 程序
    Spark 不允许在 Worker 中访问 SparkContext
    Spark 安装
  • 原文地址:https://www.cnblogs.com/developerchen/p/7776348.html
Copyright © 2011-2022 走看看