Git添加SSh公钥以及多人协作冲突问题解决方案
2017-12-20 16:10
781 查看
现在加入有两台机器想访问gitee(与github类似,csdn的代码托管平台,很好用^_^,推荐一波)
这里会进入bash 命令框
配置全局的用户名和邮箱,这个必须要配置,不然git没法commit,当然也可以单独配置每个工程的用户和邮箱这里就不说了。
生成ssh秘钥
这里生成时会出现如下的信息,直接按Enter建就好,直接放入默认位置下
还会有一个类似下面的一句话,意思让我们输密码,输不输都行,这里我输入了密码,还会让你在输入一遍,输入时密码不可见,注意。输入完秘钥应该就生成了。
查看秘钥是否生成
如果出现如下所示的秘钥(一个公钥一个私钥),恭喜,成功。
将公钥在gitee(或者github)中添加。
首先查看一下公钥
出现和下面相似的一串字符,复制它
打开你的gitee,按照图中顺序,先点击setting,找到SSH Key Setting,将Key复制到Key中,Title随便起。
完成,这样你就可以向
这是因为A提交的index.html与B提交的产生了冲突,此时应该先从gitee 重新pull一下,如下所示:
这里pull成功,但是提示有冲突,需要修改
此时我们进入index.html后会看到如下结果
如下所示的地方就是有冲突的地方,用=====隔开了,你现在可以合并它们,然后重新add,commit,push一下就可以了。
修改后的index.html如下所示:
从add到push的操作如下所示:
查看一下log,可以看到如下的日志
OK,这样就解决了冲突了
将两台电脑的SSH公钥添加到gitee中
这里我们用两种系统分别为Windows和CentosWindow
如果装过git,右键桌面,选择如下的红色标记的地方,没装的话。。(还用说么,下载安装)这里会进入bash 命令框
配置全局的用户名和邮箱,这个必须要配置,不然git没法commit,当然也可以单独配置每个工程的用户和邮箱这里就不说了。
git config --global user.name "YiwenDong" git config --global user.email "xxxx1.dong.ext@nokia.com"
生成ssh秘钥
$ ssh-keygen -t rsa -C "xxxx.1.dong.ext@nokia.com"
这里生成时会出现如下的信息,直接按Enter建就好,直接放入默认位置下
Creates a new ssh key using the provided email # Generating public/private rsa key pair. Enter file in which to save the key (/home/you/.ssh/id_rsa):
还会有一个类似下面的一句话,意思让我们输密码,输不输都行,这里我输入了密码,还会让你在输入一遍,输入时密码不可见,注意。输入完秘钥应该就生成了。
Enter same passphrase again: [Type passphrase again]
查看秘钥是否生成
$ cd ~/.ssh $ ls
如果出现如下所示的秘钥(一个公钥一个私钥),恭喜,成功。
将公钥在gitee(或者github)中添加。
首先查看一下公钥
cat id_rsa.pub
出现和下面相似的一串字符,复制它
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCcc3aFD6+QdySTy9b5O5p26JCVF86a00h530XX9mVD3QUkSG0gdEldDMrgef5N6rrHuApx13hYBuiviJj9Vp6y+6w2b6ncGnHrdPmhCOiBVQ2k1tr0DIclDb6b44QbxNU4q8D0yF+69Pj7OajUOU3JLRs9oovHXjYVXPBi11xDBYSVB3hVh9ocdVYuevCgBVBttie/wQu4ajib6zQC9984+5GSDpWLeG5bh5H7rhAm/fzpcZv+dxDGsjbCwbymQv/eBbWhECPXNb60ZIbtaR0s1vgCF9KcjAjEaBXHlvjd/KpUWX3fJVhAD87Y9+m+pRzcawHmUwTpCo/ThejkL5h9 xxxx.1.dong.ext@nokia.com
打开你的gitee,按照图中顺序,先点击setting,找到SSH Key Setting,将Key复制到Key中,Title随便起。
完成,这样你就可以向
Centos
。。不知如何写起。一句话和上面操作一模一个样,就是操作起来更舒服点,哈哈。多人协作冲突问题
假如我们在gitee中有一个项目,项目名叫Demo,现在两台电脑(A B)都将该项目克隆下来了,A现在提交了一个名字叫index.html的文件,并且push到gitee中了,而B此时也修改了index文件,在push时出现如下问题:git push origin dev Enter passphrase for key '/root/.ssh/id_rsa': To git@gitee.com:YiwenDong/Demo.git ! [rejected] dev -> dev (fetch first) error: failed to push some refs to 'git@gitee.com:YiwenDong/Demo.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 merge the remote changes (e.g., hint: 'git pull') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.
这是因为A提交的index.html与B提交的产生了冲突,此时应该先从gitee 重新pull一下,如下所示:
[root@CivenOS Demo]# git pull Enter passphrase for key '/root/.ssh/id_rsa': remote: Counting objects: 9, done. remote: Compressing objects: 100% (6/6), done. remote: Total 9 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (9/9), done. From gitee.com:YiwenDong/Demo 64236f8..35eecf5 dev -> origin/dev Auto-merging index.html CONFLICT (add/add): Merge conflict in index.html Automatic merge failed; fix conflicts and then commit the result.
这里pull成功,但是提示有冲突,需要修改
此时我们进入index.html后会看到如下结果
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <link href="css/login-all.css" rel="stylesheet"> </head> <body> <div id="login-container"> <div class="login-bg"></div> <div class="login-nav"></div> <div class="login-content"></div> </div> <div id="login-keeparea"></div> <div id="login-footer">@2017 yiwen</div> <<<<<<< HEAD <div id="test"></div> ======= <div>this is test</div> >>>>>>> 7a447f3a3ff4f05f4867658bc60f994930c00beb </body> </html>
如下所示的地方就是有冲突的地方,用=====隔开了,你现在可以合并它们,然后重新add,commit,push一下就可以了。
<<<<<<< HEAD <div id="test"></div> ======= <div>this is test</div> >>>>>>> 7a447f3a3ff4f05f4867658bc60f994930c00beb
修改后的index.html如下所示:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <link href="css/login-all.css" rel="stylesheet"> </head> <body> <div id="login-container"> <div class="login-bg"></div> <div class="login-nav"></div> <div class="login-content"></div> </div> <div id="login-keeparea"></div> <div id="login-footer">@2017 yiwen</div> <div id="test"></div> <div>this is test</div> </body> </html>
从add到push的操作如下所示:
[root@CivenOS Demo]# git add index.html [root@CivenOS Demo]# git commit -m "fixed conflicts about index.html" [dev 2a6fe7d] fixed conflicts about index.html [root@CivenOS Demo]# git push warning: push.default is unset; its implicit value is changing in Git 2.0 from 'matching' to 'simple'. To squelch this message and maintain the current behavior after the default changes, use: git config --global push.default matching To squelch this message and adopt the new behavior now, use: git config --global push.default simple See 'git help config' and search for 'push.default' for further information. (the 'simple' mode was introduced in Git 1.7.11. Use the similar mode 'current' instead of 'simple' if you sometimes use older versions of Git) Enter passphrase for key '/root/.ssh/id_rsa': Counting objects: 17, done. Compressing objects: 100% (11/11), done. Writing objects: 100% (12/12), 1.12 KiB | 0 bytes/s, done. Total 12 (delta 6), reused 0 (delta 0) To git@gitee.com:YiwenDong/Demo.git 7a447f3..2a6fe7d dev -> dev
查看一下log,可以看到如下的日志
* 2a6fe7d fixed conflicts about index.html |\ | * 7a447f3 update index.html * | f46f2ea linux update index.html * | ef193a1 merge & fix in index |\ \ | |/
OK,这样就解决了冲突了
相关文章推荐
- 添加码云上的SSH公钥以及解决使用命令git pull/push 输入密码问题
- GIT 免密登录解决多账户问题,涉及 SSH 私钥/公钥
- git ssh秘钥的添加解决克隆时没有权限的问题
- 1git命令的使用,查看git仓库状态,添加文件到git跟踪,git提交,查看git分支,查看git仓库日志信息,切换git分支,解决git分支合并后出现冲突的问题
- Windows Server VM克隆的具体步骤,以及IP冲突和域添加的问题解决
- 1git命令的使用,查看git仓库状态,添加文件到git跟踪,git提交,查看git分支,查看git仓库日志信息,切换git分支,解决git分支合并后出现冲突的问题
- 解决ssh添加用户公钥到~/.ssh/authorized_keys文件后任然无法无密码登录的问题
- web api post/put空值问题以及和angular的冲突的解决
- Eclipse Java EE IDE 添加tomcat服务器以及解决404的问题
- 关于VS2008 中添加成员变量提示 此网站的某个加载项运行失败 请检查“Internet选项”中的安全设置是否存在潜在冲突 问题解决办法
- unity3D 4.6及以上版本. UI穿透问题,以及模拟器不穿透真机穿透问题解决方案
- Git出现error: Your local changes to the following files would be overwritten by merge: ... Please, commit your changes or stash them before you can merge.的问题解决(Git代码冲突)
- git添加公钥后报错sign_and_send_pubkey: signing failed: agent refused operation的解决办法
- 如何解决Visual c++不能打开文件以及工程不能添加文件的问题
- ssh使用公钥授权不通过的问题解决
- 在xib和story board上实现代码自动布局(解决添加约束时,大于等于小于等于繁琐的问题,以及占位view的问题)
- ViewPager禁止滑动,设置页片间距,设置当前显示的页面,缓存个数,以及解决嵌套ViewPager左右滑动冲突问题
- ScrollView嵌套ListView冲突问题解决方案
- SSH 设置无需密码登陆服务器以及解决SSH登陆慢的问题
- Java web:SSH项目拷贝产生问题以及解决(getContextPath() xml hibernate等报错)