git常见问题及解决方法

目录
  1. 1. 远程已经删除的分支,但是本地还存在此分支,怎么把本地分支和远程仓库同步?
  2. 2. 报错 git: No refs in common and none specified; doing no
  3. 3. git pull push没有指定branch报错的解决方法
  4. 4. Windows无法正确执行git reset --hard HEAD^
  5. 5. git命令行在windows中报错WARNING: terminal is not fully functional
  6. 6. 移除”old mode 100755 new mode 100644”提示

远程已经删除的分支,但是本地还存在此分支,怎么把本地分支和远程仓库同步?

在你经常使用的命令当中有一个git branch –a用来查看所有的分支,包括本地和远程的。但是时间长了你会发现有些分支在远程其实早就被删除了,但是在你本地依然可以看见这些被删除的分支。

先调用git remote show origin,该命令能够获取远端分支信息,你可以看到和本地和远端不同步的地方

过时的就是和本地不同步的分支,本地已过时的表示你需要移除这个分支了。

这个时候你需要调用 git remote prune origin,同步远程的分支到本地,这样远程已经被删除的分支,本地就不会再看见了。


报错 git: No refs in common and none specified; doing no

用gitolite新建项目,clone后首次push,可能会出现:

1
2
3
4
5
$ git push  
No refs in common and none specified; doing nothing.
Perhaps you should specify a branch such as 'master'.
fatal: The remote end hung up unexpectedly
error: failed to push some refs to 'file:///xxxxxxx.git'

这是Git 找不到你要提交的版本了。
解决办法:git push origin master


git pull push没有指定branch报错的解决方法

git 执行git pushgit pull的操作时候,经常看到下面的提示:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
You asked me to pull without telling me which branch you
want to merge with, and 'branch.dev.merge' in
your configuration file does not tell me, either. Please
specify which branch you want to use on the command line and
try again (e.g. 'git pull <repository> <refspec>').
See git-pull(1) for details.

If you often merge with the same branch, you may want to
use something like the following in your configuration file:

[branch "dev"]
remote = <nickname>
merge = <remote-ref>

[remote "<nickname>"]
url = <url>
fetch = <refspec>

See git-config(1) for details.

在高版本的 git下面,也许会看见这样的提示:

1
2
3
4
5
6
7
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 master origin/<branch>

看到第二个提示,我们现在知道了一种解决方案。也就是指定当前工作目录工作分支,跟远程的仓库,分支之间的链接关系。

比如我们设置master对应远程仓库的master分支
git branch --set-upstream master origin/master
这样在我们每次想push或者pull的时候,只需要 输入git push或者git pull即可。

在此之前,我们必须要指定想要push或者pull的远程分支:
git push origin master
git pull origin master


Windows无法正确执行git reset --hard HEAD^

为何无法正确执行git reset --hard HEAD^
Git入门书里都会提到放弃最后一次的commit而回复到再上一次commit的指令:
git reset --hard HEAD^
但是这个指令在Windows的命令提示字符cmd.exe里却无法执行,会出现错误:

1
2
3
4
5
6
7
D:\git-root\test>git reset --hard HEAD^
More?
More?
fatal: ambiguous argument 'HEAD
': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git [...] -- [...]'

今天终于弄清楚了:^是cmd.exe的escape字符,属于特殊字符,命令里要用到文字^时必须用双引号把它夹起来,因此只要如下就可以正确执行:
git reset --hard HEAD"^"
或者:
git reset --hard "HEAD^"


git命令行在windows中报错WARNING: terminal is not fully functional

今天在windows的cmd窗口中执行git stash list命令的时候报错:
WARNING: terminal is not fully functional

百度了一下,解决方法如下:
1、打开windows的高级系统设置
2、环境变量
3、系统变量中新建一个变量名为TERM,值为cygwin
重新执行git命令,ok。


移除”old mode 100755 new mode 100644”提示

让git忽略掉文件权限检查:
git config core.filemode false