怎么向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
正常來說,想要在本地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!!!!!