git對不起我是個猴子……
好菜啊……
這是一篇不正經的記錄
推薦一篇教程,猴子都能懂的git入門:https://backlog.com/git-tutorial/cn/intro/intro1_1.html
git關於push到遠程數據庫失敗的解決方案
參考鏈接:https://www.jianshu.com/p/ea6ec80ad5f2
整理一個報錯信息,命令如下:
$ git remote add origin https://[your_space_id].backlogtool.com/git/[your_project_key]/tutorial.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.
問題(Non-fast-forward)的出現原因是: git倉庫中已有一部分代碼, 它不允許你直接把你的代碼覆蓋上去。於是有2個選擇方式:
-
強推,即利用強覆蓋方式用你本地的代碼替代git倉庫內的內容:
git push -f
-
先把git的東西fetch到你本地然後merge後再push
- $ git fetch
- $ git merge
這兩句命令等價於
$ git pull
可是, 有時候還會出現問題:
上面出現的 [branch “master”]是需要明確(.git/config)如下的內容
[branch “master”]
remote = origin
merge = refs/heads/master
這等於告訴git兩件事:
- 當你處於master branch, 默認的remote就是origin。
- 當你在master branch上使用git pull時,沒有指定remote和branch,那麼git就會採用默認的remote(也就是origin)來merge在master branch上所有的改變
如果不想或者不會編輯config文件的話,可以在輸入如下命令行:
$ git config branch.master.remote origin
$ git config branch.master.merge refs/heads/master
之後再重新git pull下。
最後git push即可。
刪除本地git倉庫
在本地倉庫的目錄下調用命令行刪除根目錄下的.git文件夾
find . -name “.git” | xargs rm -Rf
刪不乾淨的手動刪掉。