問題1.先創建本地庫,后拉取遠程倉庫時上傳失敗的問題怎么解決?
操作主要步驟:?
????????step1 設置遠程倉庫地址:?
????????$ git remote add origin git@gitee.com:yourAccount/reponamexxx.git
????????step2 推送到遠程倉庫:
????????$ git push -u origin "master"?
報錯信息:
To git@gitee.com:yourAccount/reponamexxx.git! [rejected] master -> master (fetch first)
error: failed to push some refs to 'gitee.com:yourAccount/reponamexxx.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
解決辦法:?
? ? ? ? ?step1 拉取遠程倉庫,使用 --allow-unrelated-histories選項,本質上是合并(merge):
????????$ git pull origin master --allow-unrelated-histories
????????
? ? ? ? step2:在來一把,不帶該選項。
????????$ git pull origin master
? ? ? ? ?step3:推送
????????$ git push -u origin "master"
????????
? ? ? ? 【注】如果是新建本地倉庫,沒有添加任何文件,只要使用如下語句就可以成功拉取。
????????$ git pull origin master
?
問題2:如何在本地用命令行創建一個git倉庫,并推送到遠程?
操作主要步驟:?
????????在本地用命令行創建一個git倉庫,并推送到遠程
????????1. [ git init ]
????????在gitStore目錄下 初始化一個git倉庫
????????2. [ git add . ] ??
????????復制一個文件到gitStore目錄下,然后執行[ git add . ]將“修改”從當前工作區存放到暫存區
????????3. [ git commit -m "first commit" ]
????????將暫存區中存放的文件提交到git倉庫?
????????4.在遠端新建一個git代碼庫:https://github.com/*******
????????5.git remote add origin https://github.com/********
????????將本地代碼庫的當前分支與遠程的代碼庫相關聯
????????6.[ git push -u origin master ]
????????將本地代碼庫的當前分支推送到遠程的代碼庫
問題3:一大堆文件中有個文件太大的導致上傳失敗怎么辦?
? ? ? ? 問題描述:
? ? ? ? 一大堆文件上傳,使用命令git push -u origin "master"后報錯了,截圖如下:????????
? ? ? ? 解決辦法:?
? ? ? ? 按照提示解決:
remote: error: File: a608078e6c02787b03158e5296ae238368d2fa1e 184.28 MB, exceeds 100.00 MB.
remote: Use command below to see the filename:
remote: git rev-list --objects --all | grep a608078e6c02787b03158e5296ae238368d2fa1e
remote: Please remove the file from history and try again. (https://gitee.com/help/articles/4232)
? ? ? ? 1.查找大文件
? ? ? ? 2.刪除緩存的文件
? ? ? ? 執行命令:
????????git filter-branch -f --prune-empty --index-filter 'git rm -rf --cached --ignore-unmatch 安全/黑客大曝光(第7版).pdf' --tag-name-filter cat -- --all
? ? ? ? 結果報錯,原因是有特殊字符()。如下:
$ git filter-branch -f --prune-empty --index-filter 'git rm -rf --cached --ignore-unmatch 黑客大曝光(第7版).pdf' --tag-name-filter cat -- --all
WARNING: git-filter-branch has a glut of gotchas generating mangled historyrewrites. Hit Ctrl-C before proceeding to abort, then use analternative filtering tool such as 'git filter-repo'(https://github.com/newren/git-filter-repo/) instead. See thefilter-branch manual page for more details; to squelch this warning,set FILTER_BRANCH_SQUELCH_WARNING=1.
Proceeding with filter-branch...Rewrite de8e55eae6658a8a271604c05607a0a44a954c05 (1/4) (0 seconds passed, remaining 0 predicted) D:/Apps/DevlopSoft/Git/mingw64/libexec/git-core\git-filter-branch: eval: line 439: syntax error near unexpected token `('
D:/Apps/DevlopSoft/Git/mingw64/libexec/git-core\git-filter-branch: eval: line 439: `git rm -rf --cached --ignore-unmatch 黑客大曝光(第7版).pdf'
? ? ? ? 直覺可以用轉義字符來解決,執行如下命令,果然可以。
$ git filter-branch -f --prune-empty --index-filter 'git rm -rf --cached --ignore-unmatch 黑客大曝光\(第7版\).pdf' --tag-name-filter cat -- --all
? ? ? ? ? 3.重新推送
?????????????????$ git push -u origin "master" --force
????????
? ? ? ? ? ? ? ?還是推送失敗怎么辦?查詢了下還是一樣的。
?????????$ git rev-list --objects --all | grep a608078e6c02787b03158e5296ae238368d2fa1e ?a608078e6c02787b03158e5296ae238368d2fa1e 安全/黑客大曝光(第7版).pdf????????
????????git 如何刪除本地已經提交了的超過100M的文件
????????要刪除Git倉庫中已經提交的大于100M的文件,你可以按照以下步驟操作:
- 找到提交記錄中包含大文件的commit的哈希值。
- 使用
git rm --cached
命令從索引中移除大文件,但保留在本地磁盤上。 - 修改最近的提交以移除大文件。
- 強制推送到遠程倉庫。
????????以下是具體的命令:
git log --oneline # 查找包含大文件的commit的哈希值
git rm --cached -r path_to_large_file # 將大文件從Git索引中移除
git commit --amend --no-edit # 修改最近的提交
git push origin your_branch_name --force # 強制推送到遠程倉庫
?
????????git commit --amend --no-edit # 修改最近的提交?
?
? ? ? ? ?效果:
? ? ? ? 如下圖推送成功。
????????
?
問題4:gitee單文件單庫大小限制怎么辦?
? ? ? ? 單文件100M,單庫500M限制,如果有需求,請參考如下解決辦法:?
? ? ? ? 參考:解決文件傳輸難題:如何繞過Gitee的100MB上傳限制_gitee上傳大于100m的文件-CSDN博客