Git常见问题解决办法

Q:fatal: not a git repository (or any of the parent directories): .git
K:产生原因:一般是没有初始化git本地版本管理仓库,
所以无法执行git命令
解决方法:操作之前执行以下命令行: git init 然后执行一下git status查看状态信息,即可;

二、git获取远程代码,让远程代码直接覆盖本地代码

git fetch --all //只是下载代码到本地,不进行合并操作
git reset --hard origin/master //把HEAD指向最新下载的版本

三、

Git常见问题解决办法

Pull is not possible because you have unmerged files.

问题:pull的时候

$ git pull

Pull is not possible because you have unmerged files.
Please, fix them up in the work tree, and then use 'git add/rm <file>'
as appropriate to mark resolution, or use 'git commit -a'

应是local文件冲突了

解决方法:  

1.pull会使用git merge导致冲突,需要将冲突的文件resolve掉 git add -u, git commit之后才能成功pull.

2.如果想放弃本地的文件修改,可以使用git reset --hard FETCH_HEAD,FETCH_HEAD表示上一次成功git pull之后形成的commit点。然后git pull.
注意:

git merge会形成MERGE-HEAD(FETCH-HEAD) 。git push会形成HEAD这样的引用。HEAD代表本地最近成功push后形成的引用。 

有时候会莫名其妙地出现这状况,且Untracked files 还特别多(实际上自己可能只改了个别文件),只好先保存好自己确定做出的local的修改,用git reset --hard FETCH_HEAD回到上次成功pull之后的点,然后再pull就没有问题了 

四、You are not currently on a branch.

问题:pull的时候又出现冲突 ,出现:

$ git pull      You are not currently on a branch, so I cannot use any
'branch.<branchname>.merge' in your configuration file.
Please specify which remote branch you want to use on the command
line and try again (e.g. 'git pull <repository> <refspec>').
See git-pull(1) for details.
解决方法:

首先git checkout -b temp

其次git checkout master

即可恢复到master repository的状态,然后就可以pull了

五、fatal: Not a git repository (or any of the parent directories): .git
翻译:
致命错误:不是git存储库(或任何父目录):.git
产生原因:一般是没有初始化git本地版本管理仓库,所以无法执行git命令;或者是不再clone项目的父节点下
解决方法:操作之前执行以下命令行: git init
需要在clone目录的父文件下 执行git init
之后进行上传或者合并文件