git配置和常用命令
2016-03-10 18:15
447 查看
1,在本地生成key: ssh-keygen -t rsa -C "xxx900@qq.com"
2,把生成的/home/zhuyi/.ssh/id_rsa.pub中全部内容复制, 粘贴到github网站上add key
3,测试连接:ssh -T git@github.com
4,配置本地git:
git config --global user.name "july11"
git config --global user.email "xxx900@qq.com"
如果为本地git库配置多用户,那么这里就不能设置global的
要在每个git库目录下配置对应的用户:
git config user.name "july11"
5,本地git配置多用户
一个host一个key,注意第二个ssh-keygen时key file不能使用默认的名字,我设第二个为gitosc
如果是只有github托管,有多个github帐号,则可将第二个用户的设置改为:HOST 修改.ssh目录下的config, 设置多个host,这里是多用户多个托管地址,在github和gitosc分别托管项目。
如果只是在github上托管,有多个帐号,则把第二个的设置改一下:HOST two.github.com
修改第二个帐号的git库配置:
详细参考:
http://tmyam.github.io/blog/2014/05/07/duo-githubzhang-hu-she-zhi/ http://blog.csdn.net/itmyhome1990/article/details/42643233
6,clone一个project到本地:
git clone git@github.com:july11/july11.github.com.git
现在都推荐使用https的链接,但是如果clone https的会引起一个问题,就是每次pull或者push都需要输入用户名和密码,相当麻烦,改以下配置即可:
修改git项目根目录下的.git文件夹下的config文件:
7,提交一个版本, 远程仓库没有修改的情况
查看本地git库修改状态: git status
添加所有修改的文件: git add .
提交: git commit -m "change log"
push到远程主干: git push origin master
8, 远程仓库已修改的情况
git push时提示有冲突
先从远程库拉一份最新的: git pull
查看冲突: git status
8.1 手动解决冲突:
打开冲突文件 HEAD<<< 到 === 之间是本地的修改, === 到 >>> 之间是远程仓库的修改
手动修改后, 去掉这些标记
8.2 用mergetool
9, 解决冲突后的提交:
合入主干(merge): git commit -a
把修改后的文件添加: git add <file>
提交本地仓库: git commit -m ""
push到远程主干: git push origin master
工具: gitk 查看status
工具: mergetool在界面中解决冲突
10, 分支相关
查看本地当前分支: git branch
查看本地和远程所有分支: git branch -va
切换到一个远程分支: git checkout -t origin/<branch name>
11, 撤销提交
git push时提示有大文件不能上传
remote: warning: Large files detected.
remote: error: File featureExtract/ScaCtm/bow_test_Sca.txt is 173.91 MB; this exceeds Git@OSC's file size limit of 100 MB
remote: error: hook declined to update refs/heads/master
查看提交日志:git reflog
1118157 HEAD@{0}: commit: update to support folder vocabulary
6abbb56 HEAD@{1}: commit: code on bigdisk upgraded to add folder vocabulary
263473a HEAD@{2}: clone: from https://git.oschina.net/sdlucaslala/scene.git
要回退到HEAD 2:
git reset HEAD~2
再重新add, commit,push
12, 忽略文件或文件夹
在仓库根目录下 vi .gitignore
添加如下内容:
/data
/bin
保存即可
13, 本地已有项目
在git网站创建新代码库,假设地址为git@git.oschina.net:july/proj.git
进入本地项目根目录下:
cd proj
git init
git remote add origin git@git.oschina.net:july/proj.git
vim .gitignore #添加要忽略提交的目录或文件
git add src/ #添加要提交到远程仓库的文件
git commit -a -m "first commit"
git pull origin master
git push origin master
2,把生成的/home/zhuyi/.ssh/id_rsa.pub中全部内容复制, 粘贴到github网站上add key
3,测试连接:ssh -T git@github.com
4,配置本地git:
git config --global user.name "july11"
git config --global user.email "xxx900@qq.com"
如果为本地git库配置多用户,那么这里就不能设置global的
要在每个git库目录下配置对应的用户:
git config user.name "july11"
5,本地git配置多用户
一个host一个key,注意第二个ssh-keygen时key file不能使用默认的名字,我设第二个为gitosc
如果是只有github托管,有多个github帐号,则可将第二个用户的设置改为:HOST 修改.ssh目录下的config, 设置多个host,这里是多用户多个托管地址,在github和gitosc分别托管项目。
Host github.com HostName github.com User git IdentityFile ~/.ssh/id_rsa Host git.oschina.net HostName git.oschina.net User git IdentityFile ~/.ssh/gitosc
如果只是在github上托管,有多个帐号,则把第二个的设置改一下:HOST two.github.com
修改第二个帐号的git库配置:
it remote rm origin git remote add origin git@two.github.com:[name2]/two.github.com.git
详细参考:
http://tmyam.github.io/blog/2014/05/07/duo-githubzhang-hu-she-zhi/ http://blog.csdn.net/itmyhome1990/article/details/42643233
6,clone一个project到本地:
git clone git@github.com:july11/july11.github.com.git
现在都推荐使用https的链接,但是如果clone https的会引起一个问题,就是每次pull或者push都需要输入用户名和密码,相当麻烦,改以下配置即可:
修改git项目根目录下的.git文件夹下的config文件:
[remote "origin"] url = git@github.com:suyan/suyan.github.io.git fetch = +refs/heads/*:refs/remotes/origin/*
7,提交一个版本, 远程仓库没有修改的情况
查看本地git库修改状态: git status
添加所有修改的文件: git add .
提交: git commit -m "change log"
push到远程主干: git push origin master
8, 远程仓库已修改的情况
git push时提示有冲突
先从远程库拉一份最新的: git pull
查看冲突: git status
8.1 手动解决冲突:
打开冲突文件 HEAD<<< 到 === 之间是本地的修改, === 到 >>> 之间是远程仓库的修改
手动修改后, 去掉这些标记
8.2 用mergetool
9, 解决冲突后的提交:
合入主干(merge): git commit -a
把修改后的文件添加: git add <file>
提交本地仓库: git commit -m ""
push到远程主干: git push origin master
工具: gitk 查看status
工具: mergetool在界面中解决冲突
10, 分支相关
查看本地当前分支: git branch
查看本地和远程所有分支: git branch -va
切换到一个远程分支: git checkout -t origin/<branch name>
11, 撤销提交
git push时提示有大文件不能上传
remote: warning: Large files detected.
remote: error: File featureExtract/ScaCtm/bow_test_Sca.txt is 173.91 MB; this exceeds Git@OSC's file size limit of 100 MB
remote: error: hook declined to update refs/heads/master
查看提交日志:git reflog
1118157 HEAD@{0}: commit: update to support folder vocabulary
6abbb56 HEAD@{1}: commit: code on bigdisk upgraded to add folder vocabulary
263473a HEAD@{2}: clone: from https://git.oschina.net/sdlucaslala/scene.git
要回退到HEAD 2:
git reset HEAD~2
再重新add, commit,push
12, 忽略文件或文件夹
在仓库根目录下 vi .gitignore
添加如下内容:
/data
/bin
保存即可
13, 本地已有项目
在git网站创建新代码库,假设地址为git@git.oschina.net:july/proj.git
进入本地项目根目录下:
cd proj
git init
git remote add origin git@git.oschina.net:july/proj.git
vim .gitignore #添加要忽略提交的目录或文件
git add src/ #添加要提交到远程仓库的文件
git commit -a -m "first commit"
git pull origin master
git push origin master
相关文章推荐
- 一文看懂大数据的技术生态圈,Hadoop,hive,spark都有了
- 实用ListView加载提示工具类
- HDU 2.1.4 又见GCD
- 数据库表查询的一些知识点
- while (cin>>str)退出死循环
- A. Interview
- Android 中的依赖注入框架
- HDU 2.1.3 Cake
- HDU 2.1.2 How many prime numbers
- 转载 最大熵模型介绍及实现
- 第2周项目3—小试循环(5)
- S2SM项目tomcat启动停在Initializing Spring root WebApplicationContext
- poj 1797 Heavy Transportation(最短路径Dijkdtra)
- 股神巴菲特对股市本质的形象解释
- Linux最常用指令及快捷键 Linux学习笔记
- Windows环境将应用设置成服务
- HDU 2.1.1 最小公倍数
- 引入sleak异常,Warning: Device is not tracking resource allocation处理
- 在Eclipse中编写servlet时出现"The import javax.servlet cannot be resolved" 问题解决办法
- 欢迎使用CSDN-markdown编辑器