Git之问题篇

来源:互联网 发布:专车软件有哪些 编辑:程序博客网 时间:2024/04/28 03:03

 转自:http://blog.csdn.net/dengjianqiang2011/article/details/9260435

如果输入$Git remote add origingit@github.com:djqiang(github帐号名)/gitdemo(项目名).git 

    提示出错信息:fatal: remote origin already exists.

    解决办法如下:

    1、先输入$ git remote rm origin

    2、再输入$ git remote add origingit@github.com:djqiang/gitdemo.git 就不会报错了!

    3、如果输入$ git remote rm origin还是报错的话,error: Could not remove config section 'remote.origin'. 我们需要修改gitconfig文件的内容

    4、找到你的github的安装路径,我的是C:\Users\ASUS\AppData\Local\GitHub\PortableGit_ca477551eeb4aea0e4ae9fcd3358bd96720bb5c8\etc

    5、找到一个名为gitconfig的文件,打开它把里面的[remote "origin"]那一行删掉就好了!

 

 

    如果输入$ ssh -Tgit@github.com
    出现错误提示:Permission denied (publickey).因为新生成的key不能加入ssh就会导致连接不上github。

    解决办法如下:

    1、先输入$ ssh-agent,再输入$ ssh-add ~/.ssh/id_key,这样就可以了。

    2、如果还是不行的话,输入ssh-add ~/.ssh/id_key 命令后出现报错Could not open a connection to your authentication agent.解决方法是key用Git Gui的ssh工具生成,这样生成的时候key就直接保存在ssh中了,不需要再ssh-add命令加入了,其它的user,token等配置都用命令行来做。

    3、最好检查一下在你复制id_rsa.pub文件的内容时有没有产生多余的空格或空行,有些编辑器会帮你添加这些的。

 

 

    如果输入$ git push origin master

    提示出错信息:error:failed to push som refs to .......

    解决办法如下:

    1、先输入$ git pull origin master //先把远程服务器github上面的文件拉下来

    2、再输入$ git push origin master

    3、如果出现报错 fatal: Couldn't find remote ref master或者fatal: 'origin' does not appear to be a git repository以及fatal: Could not read from remote repository.

    4、则需要重新输入$ git remote add origingit@github.com:djqiang/gitdemo.git

 

 

    使用git在本地创建一个项目的过程

    $ makdir ~/hello-world    //创建一个项目hello-world
    $ cd ~/hello-world       //打开这个项目
    $ git init             //初始化
    $ touch README
    $ git add README        //更新README文件
    $ git commit -m 'first commit'     //提交更新,并注释信息“first commit”
    $ git remote add origin git@github.com:defnngj/hello-world.git     //连接远程github项目 
    $ git push -u origin master     //将本地项目更新到github项目上去

 

   

    gitconfig配置文件

         Git有一个工具被称为git config,它允许你获得和设置配置变量;这些变量可以控制Git的外观和操作的各个方面。这些变量可以被存储在三个不同的位置:
         1./etc/gitconfig 文件:包含了适用于系统所有用户和所有库的值。如果你传递参数选项’--system’ 给 git config,它将明确的读和写这个文件。
         2.~/.gitconfig 文件 :具体到你的用户。你可以通过传递--global 选项使Git 读或写这个特定的文件。
         3.位于git目录的config文件 (也就是 .git/config) :无论你当前在用的库是什么,特定指向该单一的库。每个级别重写前一个级别的值。因此,在.git/config中的值覆盖了在/etc/gitconfig中的同一个值。
        在Windows系统中,Git在$HOME目录中查找.gitconfig文件(对大多数人来说,位于C:\Documents and Settings\$USER下)。它也会查找/etc/gitconfig,尽管它是相对于Msys 根目录的。这可能是你在Windows中运行安装程序时决定安装Git的任何地方。

 

        配置相关信息:

        2.1 当你安装Git后首先要做的事情是设置你的用户名称和e-mail地址。这是非常重要的,因为每次Git提交都会使用该信息。它被永远的嵌入到了你的提交中:

  $ git config --global user.name "John Doe"

  $ git config --global user.emailjohndoe@example.com

 

       2.2    你的编辑器(Your Editor)

  现在,你的标识已经设置,你可以配置你的缺省文本编辑器,Git在需要你输入一些消息时会使用该文本编辑器。缺省情况下,Git使用你的系统的缺省编辑器,这通常可能是vi或者 vim。如果你想使用一个不同的文本编辑器,例如Emacs,你可以做如下操作:

  $ git config --global core.editor emacs

 

      2.3 检查你的设置(Checking Your Settings)

  如果你想检查你的设置,你可以使用 git config --list命令来列出Git可以在该处找到的所有的设置:

  $ git config --list

      你也可以查看Git认为的一个特定的关键字目前的值,使用如下命令 git config {key}:

  $ git config user.name

 

      2.4 获取帮助(Getting help)

  如果当你在使用Git时需要帮助,有三种方法可以获得任何git命令的手册页(manpage)帮助信息:

  $ git help <verb>

  $ git <verb> --help

  $ man git-<verb>

  例如,你可以运行如下命令获取对config命令的手册页帮助:

  $ git help config


----------------------------------------------------------------------------------------------------------------------------

2.To https://github.com/Airfald/IFE_Task01.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/Airfald/IFE_Task01.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.


git push 不成功问题,其实问题很简单,略懂英文的基本可以知道是什么意思。

经过查询基本意思就是你在Github上的内容和本地的内容不一致,比如说你在之前已经在其它的地方提交过,

或是你直接在Github上有改动,经过我的排查发现Github上创建新的仓库的时候比本地多了一个README.MD文件所以导致本地的与远程的

不一致

具体参考:http://www.crifan.com/git_github_git_push_origin_master_error_failed_to_push_some_refs_to/

              http://stackoverflow.com/questions/24114676/git-error-failed-to-push-some-refs-to

【解决过程】

1.看到提示里面,感觉是本地的代码不是最新的。

所以觉得应该是类似于svn中的,先update一下,再去commit,估计就可以了。

所以先去pull试试:

结果直接pull好像是不对的:

do git pull from local fail

 

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
Administrator@PC-20131018OHXV/cygdrive/e/dev_root/git/crifanLib
$ git pull
warning: no common commits
remote: Counting objects: 6,done.
remote: Total 6 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (6/6),done.
From https://github.com/crifan/crifanLib
 * [new branch]      master     -> origin/master
You asked me to pull without telling mewhich branch you
want to merge with, and'branch.master.merge' in
your configurationfile does not tell me, either. Please
specify which branch you want to use on thecommand 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 followingin your configurationfile:
    [branch"master"]
    remote = <nickname>
    merge = <remote-ref>
 
    [remote"<nickname>"]
    url = <url>
    fetch = <refspec>
 
See git-config(1)for details.

看来需要先搞懂pull的用法。

2.估计是指定对应的要pull的目标即可。

所以再去试试pull origin:

pull origin still not work

?
1
2
3
4
5
Administrator@PC-20131018OHXV/cygdrive/e/dev_root/git/crifanLib
$ 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 commandline.

也还是不对。

有空再继续搞懂原理后再弄。。

3.搜:

error: failed to push some refs to

参考:

github – git error: failed to push some refs to – Stack Overflow

去试试:

try git pull rebase origin master

?
1
2
3
4
5
6
Administrator@PC-20131018OHXV/cygdrive/e/dev_root/git/crifanLib
$ git pull --rebase origin master
From https://github.com/crifan/crifanLib
 * branch            master     -> FETCH_HEAD
First, rewinding head to replay your work ontop of it...
Applying: add local crifanLib to github

可以看到,此时已经把github上最新的文件下载下来了:

now have downloded readme.md file from github repo

即,那个README.md文件。

4.接着再去:

git push origin master

now do git push origin master ok

?
1
2
3
4
5
6
7
8
9
10
11
Administrator@PC-20131018OHXV/cygdrive/e/dev_root/git/crifanLib
$ git push origin master
Username for'https://github.com':
Password for'https://crifancrifancrifan@github.com':
Counting objects: 19,done.
Delta compression using up to 4 threads.
Compressing objects: 100% (14/14),done.
Writing objects: 100% (18/18), 112.33 KiB,done.
Total 18 (delta 0), reused 0 (delta 0)
To https://github.com/crifan/crifanLib.git
   6bae951..32d67c7  master -> master

 

即可成功把本地的文件都上传到github上面去了
0 0
原创粉丝点击