git错误记录

未有特别说明均为原创,转载请注明出处

1.查看远程仓库地址:git remote show origin
2.假如你没有了.git文件夹。那么你做操作时候可能报错

fatal: Not a git repository (or any of the parent directories): .git

提示说没有.git这样一个目录,解决办法如下:

git init

但是你只是生成了一个空的git文件,没有任何关于仓库和版本的信息。
所以你还会遇到下面错误

 $ git remote show origin
 
fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.


解决办法1是设置仓库url

 git remote set-url origin https://gitee.com/XXX/XXX
 //当然我们这里新建的.git文件没有仓库,如果有的话,先删后建
git remote rm origin
git remote add origin [url]
//也可以直接修改config文件

2是将关联远程仓库为origin

git remote add origin git@github:YOUACCOUNT/YOURPROJECT.git
 

注意上面我猜应该是用master.但是我用于origin,所以发生了一些列有趣的事情。

gin https://gitee.com/XXX/XXX
PS F:\Git\XXX> git remote show origin
* remote origin
 Fetch URL: https://gitee.com/XXX/XXX
 Push  URL: https://gitee.com/XXX/XXX
 HEAD branch: master
 Remote branch:
   master new (next fetch will store in remotes/origin)

可以看到查询远程仓库地址是origin
先不管,我们头大直接提交

git add -A
git commit -m "--"
git pull

好了pull出问题了

PS F:\Git\XXX> git pull
From https://gitee.com/XXX/XXX
 * [new branch]      master     -> origin/master
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.

    git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

    git branch --set-upstream-to=origin/<branch> master

意思是拉错分支了。所以

git pull origin master
From https://gitee.com/XXX/XXX
 * branch            master     -> FETCH_HEAD
fatal: refusing to merge unrelated histories
//所以正确的应该是
git pull origin master --allow-unrelated-histories

//如果你仍然硬着头皮拉 
//git pull origin
/*
You asked to pull from the remote 'origin', but did not specify
a branch. Because this is not the default configured remote
for your current branch, you must specify a branch on the command line.
*/
//或者 git pull remote origin
/*
fatal: 'remote' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
*/

之后 如果有冲突记得合并冲突,重新
add\commit\pull origin master --allow-unrelated-histories
步骤同上
最后提交

 git push --set-upstream origin master
posted @ 2019-07-31 00:23  marvelousone  阅读(370)  评论(0编辑  收藏  举报