首页 > *nix应用编程 > Windows上git使用

Windows上git使用

2014年6月20日 发表评论 阅读评论 12,728 次浏览

1,http://msysgit.github.io/,下载安装Git-1.9.4-preview20140611.exe

2,打开Git Bash终端,执行:ssh-keygen -t rsa -C “lenky0401@163.com”
注意把命令里邮箱地址改成自己在gitlab上的注册邮箱,在这个页面https://gitlab.com/profile可以看到。
一直敲回车即可。

Lenky@LENKY-ACER ~
$ ssh-keygen -t rsa -C "lenky0401@163.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/Lenky/.ssh/id_rsa):
Created directory '/c/Users/Lenky/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/Lenky/.ssh/id_rsa.
Your public key has been saved in /c/Users/Lenky/.ssh/id_rsa.pub.
The key fingerprint is:
5c:5d:e2:13:ea:72:4d:f8:ed:36:6e:6e:cf:1d:b2:b0 lenky0401@163.com

3,把/c/Users/<用户名>/.ssh/id_rsa.pub的文件内容拷贝到这里:https://gitlab.com/profile/keys/new

Lenky@LENKY-ACER ~/.ssh
$ cat /c/Users/Lenky/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAvTbj/+kj6Y/1NEhC6KTHoBLrKik+mO5nH1CWZ3I4+uk0x/PPJvKhitskcUqHZix0HH2LJkruvxhxP98X+kz9V5tBu3lQc7ENbl5ASaj5grMLUuDCzlZNLUITuHg3iXWR/Je/toKqqGQ3YQGPFFGUKmT+PTt8/+pkCCTYaQv6S/IGZXK1cYNZHKa1Ivw36o1s/AAP8eeAJYIigFnWTK0KrC9zolXUpF/90Lgj1BfeXra7zZIIE6h+y1A9cNoKI1AY763MtCGMcoMzDzOaQcIPzErwgNHEa6IIzDZNc4F/Unps5+2yqh/sqi8ne9UYJ5Q3L6mQV8EPPV/Ts5wehUvh+w== lenky0401@163.com

注意需要确保Key里的数据没有换行(如果直接从Git Bash终端粘贴出来的,可能会拷贝到换行符),否则出现错误:
Key is invalid
Fingerprint has already been taken
Fingerprint cannot be generated

4,在项目网页https://gitlab.com/des2008/xuezhan上进行操作,fork该项目到个人首页(虽然目前我们都对最上游项目Ivan/xuezhan有权限,但还是建议先fork到自己的项目,或建立分支也行,这样好控制)。
5,在Git Bash终端里切换到项目目录,比如我这里是D:\gitlab,把个人项目代码克隆下来。如果采用https协议,则需要输入gitlab账号,如果采用ssh协议,因为前面配置过key,所以无法再做验证。

Lenky@LENKY-ACER ~
$ cd /d/gitlab/

Lenky@LENKY-ACER /d/gitlab
$ git clone https://gitlab.com/lenky.gao/xuezhan.git
Cloning into 'xuezhan'...
Username for 'https://gitlab.com': lenky0401@163.com
Password for 'https://lenky0401@163.com@gitlab.com':
remote: Counting objects: 40, done.
remote: Compressing objects: 100% (29/29), done.
remote: Total 40 (delta 3), reused 0 (delta 0)
Unpacking objects: 100% (40/40), done.
Checking connectivity... done.

Lenky@LENKY-ACER /d/gitlab
$ rm -fr xuezhan/

Lenky@LENKY-ACER /d/gitlab
$ git clone git@gitlab.com:lenky.gao/xuezhan.git
Cloning into 'xuezhan'...
The authenticity of host 'gitlab.com (62.204.93.103)' can't be established.
RSA key fingerprint is b6:03:0e:39:97:9e:d0:e7:24:ce:a3:77:3e:01:42:09.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'gitlab.com,62.204.93.103' (RSA) to the list of known
 hosts.
remote: Counting objects: 40, done.
remote: Compressing objects: 100% (29/29), done.
remote: Total 40 (delta 3), reused 0 (delta 0)
Receiving objects: 100% (40/40), 565.57 KiB | 96.00 KiB/s, done.
Resolving deltas: 100% (3/3), done.
Checking connectivity... done.

6,本地修改代码,然后提交到个人项目。

Lenky@LENKY-ACER /d/gitlab
$ cd xuezhan/

Lenky@LENKY-ACER /d/gitlab/xuezhan (master)
$ ls
AndroidManifest.xml  gen   proguard-project.txt  res
bin                  libs  project.properties

Lenky@LENKY-ACER /d/gitlab/xuezhan (master)
$ touch.exe README

Lenky@LENKY-ACER /d/gitlab/xuezhan (master)
$ git add README

Lenky@LENKY-ACER /d/gitlab/xuezhan (master)
$ git commit -m "Add README"

*** Please tell me who you are.

Run

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: unable to auto-detect email address (got 'Lenky@Lenky-Acer.(none)')

Lenky@LENKY-ACER /d/gitlab/xuezhan (master)
$ git config --global user.email "lenky0401@163.com"

Lenky@LENKY-ACER /d/gitlab/xuezhan (master)
$ git config --global user.name "lenky.gao"

Lenky@LENKY-ACER /d/gitlab/xuezhan (master)
$ git commit -m "Add README"
[master 1397a80] Add README
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 README

Lenky@LENKY-ACER /d/gitlab/xuezhan (master)
$ git push origin master
Counting objects: 4, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 271 bytes | 0 bytes/s, done.
Total 3 (delta 1), reused 0 (delta 0)
To git@gitlab.com:lenky.gao/xuezhan.git
   b38de5d..1397a80  master -> master

Lenky@LENKY-ACER /d/gitlab/xuezhan (master)
$

email和name只需设置一次,我上面是设置的全局的,也可以针对每个项目进行设置。
上面的示例里是新增一个README文件,然后通过add加入到git里,通过commit里进行提交到本地分支,通过push推倒远程的主分支,也就是我的个人项目。

7,把我的修改推到最上游,也就是由我的个人项目lenky/xuezhan推到Ivan/xuezhan,代码由Ivan进行审核是否Accept合入或Reject拒绝。
我之前在github那边使用git向上游提交代码时,这个操作我都是在网页上进行的,gitlab这边也可以这样操作:
a,在个人项目页https://gitlab.com/lenky.gao/xuezhan点击Merge Requests链接到达https://gitlab.com/lenky.gao/xuezhan/merge_requests
b,点击New Merge Request,进入到https://gitlab.com/lenky.gao/xuezhan/merge_requests/new,选择对应的分支。即把源分支(个人项目)往目标分支(上游项目路)进行推送,点击Compare branches,填写相关信息,然后制定由谁审核,进行提交。
在最上游项目就可以看到这个提交请求,审核者可以Accept或修改或直接Close掉(也就是不接受而拒绝了)。

转载请保留地址:http://www.lenky.info/archives/2014/06/2413http://lenky.info/?p=2413


备注:如无特殊说明,文章内容均出自Lenky个人的真实理解而并非存心妄自揣测来故意愚人耳目。由于个人水平有限,虽力求内容正确无误,但仍然难免出错,请勿见怪,如果可以则请留言告之,并欢迎来讨论。另外值得说明的是,Lenky的部分文章以及部分内容参考借鉴了网络上各位网友的热心分享,特别是一些带有完全参考的文章,其后附带的链接内容也许更直接、更丰富,而我只是做了一下归纳&转述,在此也一并表示感谢。关于本站的所有技术文章,欢迎转载,但请遵从CC创作共享协议,而一些私人性质较强的心情随笔,建议不要转载。

法律:根据最新颁布的《信息网络传播权保护条例》,如果您认为本文章的任何内容侵犯了您的权利,请以Email或书面等方式告知,本站将及时删除相关内容或链接。

分类: *nix应用编程 标签:
  1. 本文目前尚无任何评论.
  1. 本文目前尚无任何 trackbacks 和 pingbacks.