Git - 操作指南

1.查看配置

git config --list

 

2.添加配置

git config --global user.email "928532756@qq.com"
git config --global user.name "dragon8github"

 

3. 使用下面方式永久记住账号密码

建议用这种方式公用 github 和 gitlab ,前者可以用 ssh,后者直接用 http ,然后记住密码即可。

git config --global credential.helper store
git config --system --unset credential.helper

 

4. 设置 SSH

如果我要存储两个ssh(公司gitlab的shh和自己github的ssh)应该怎么办?:http://www.jianshu.com/p/f7f4142a1556

如果使用码云则参考这个:http://git.mydoc.io/?t=154712

1、进入C:\Users\Administrator\.ssh 先清空原本的公私钥

2、下载git并且进入到类似D:\Git\usr\bin目录中

3、ssh-keygen -t rsa -C "928532756@qq.com" --连续按三下空格

4、将C:\Users\Administrator\.ssh 中的id_rsa.pub上传到github上

5、ssh -T git@github.com --注意,这里真的是git@github.com,不需要更改其他

----

如果出现ssh: connect to host github.com port 22: Connection timed out
请使用这个:ssh -T -p 443 git@ssh.github.com
当出现Are you sure you want to continue connecting (yes/no)? 的时候,请手动输入yes

设置成功之后,所有的remote 全部要改为 ssh 如:git@github.com:dragon8github/backbone.git

(可选)如果还是无法 pull,可能是你当前网络限制 github.com(譬如政府网络),尝试切换热点尝试。

(可选)如果还是无法 pull,尝试以下代码加入到 git目录/etc/ssh/ssh_config

Host github.com
User 928532756@qq.com
Hostname ssh.github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
Port 443

 

如果你是mac用户:

第1、2步其实可有可无吧

第3步生成代码为:$ ssh-keygen -t rsa -C "928532756@qq.com"

第4步生成后的秘钥放在: $ cd ~/.ssh

其他基本一样。

 

fatal: Authentication failed 的解决方案

https://www.jianshu.com/p/8a7f257e07b8

解决方案很简单: 进入  C:\Users\用户名\.gitconfig  只留下类似以下内容

[user]
    name = chencheng
    email = 15875658583@163.com

这可能是因为之前使用了 credential.helper 缓存账户密码导致的问题。

但试了上面的方法还不行,就用管理员方式打开命令行,然后运行: git config --system --unset credential.helper

 

git 提交时遇到中文的乱码问题

 git config --global core.quotepath false
 

 

1、fatal: unable to access 'https://github.com/git/git.git/': SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

解决方案: 将git remote 的HTTPS地址 修改为 SSH 地址即可

 

2、git push -u origin master 报错

$ git push -u origin master
To https://github.com/dragon8github/es6-Study-Notes.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/dragon8github/es6-Study-Notes.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

解决方法:http://blog.csdn.net/u013120247/article/details/53263169

使用命令:git pull --rebase origin master 然后再尝试 git push -u origin master

 

版本回退

git log
git reset --hard <commit id>
或者
git checkout <commit id>

回滚之后,原来最新的历史会不见 git log ,但可以通过 git reflog 来查看。

然后又可以使用 reset 和 checkout 回去。

如果想回去最新本地版本,直接使用:git checkout  HEAD@{1} 

然后还得 git checkout master 吧。我刚刚测试的

 

posted @ 2016-05-09 15:35  贝尔塔猫  阅读(795)  评论(0)    收藏  举报