`

git 使用方法及问题

 
阅读更多

1.GIT的使用

写道
git init //创建新仓库
git add <filename> //仓库中添加文件
git add * 添加所有未在版本中的文件
git diff <source_branch> <target_branch> //对比版本
git clone /path/to/repositoty //串创建一个本地仓库的克隆版本
git clone username@host:/path/to/repository //如果是远程服务器上的仓库
git fetch origin //返回远程服务器上面的仓库
git reset --hard origin/master //获取当前版本的代码,本地改动缓存会被清空
git commit -m "代码提交信息" //提交到本地版本库中
git push origin master //推送到远程服务器中
git remote add origin <server> //添加到未克隆的版本服务器上
git checkout -b feature_x //创建一个分支,并切换到该分支上去
git checkout master //切换到主干上
git branch -d feature_x //删除分支
git push origin <branch> //推送分支到服务器上
git pull //版本更新
git fetch //获取
git merge <branch> //合并
git diff <source_branch> <target_branch>
git checkout -- <filename> //替换本地修改的文件

 

 

 

注:

git pull git fetch 的区别

git fetch 只是从服务器上获取最新的代码, 而git pull 则是获取最新代码后,并与本地代码的merge合并的结果。相当于执行了以下

git fetch origin master:tmp
git diff tmp 
git merge tmp

 

 2.git 生成key文件及设置

一 、

设置Git的user name和email:

$ git config --global user.name "xuhaiyan"
$ git config --global user.email "haiyan.xu.vip@gmail.com"

 

二、生成SSH密钥过程:
1.查看是否已经有了ssh密钥:cd ~/.ssh
如果没有密钥则不会有此文件夹,有则备份删除
2.生存密钥:

$ ssh-keygen -t rsa -C “haiyan.xu.vip@gmail.com”
按3个回车,密码为空。


Your identification has been saved in /home/tekkub/.ssh/id_rsa.
Your public key has been saved in /home/tekkub/.ssh/id_rsa.pub.
The key fingerprint is:
………………

 

最后得到了两个文件:id_rsa和id_rsa.pub


3.添加密钥到ssh:ssh-add 文件名
需要之前输入密码。
4.在github上添加ssh密钥,这要添加的是“id_rsa.pub”里面的公钥。

打开https://github.com/ ,登陆xuhaiyan825,然后添加ssh。

5.测试:ssh git@github.com

The authenticity of host ‘github.com (207.97.227.239)’ can’t be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘github.com,207.97.227.239′ (RSA) to the list of known hosts.
ERROR: Hi tekkub! You’ve successfully authenticated, but GitHub does not provide shell access
Connection to github.com closed.

多客户端配置

http://my.oschina.net/csensix/blog/184434

http://blog.csdn.net/hustpzb/article/details/8230454/

 

3.GIT权限设置

http://blog.csdn.net/mcgrady_tracy/article/details/40658251

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics