ygwin 的安装非常简单,先在其官方网站 http://www.cygwin.com/下载安装程序—一个只有几百KB的setup.exe文件,然后即可开始安装。 (1) 安装过程中会让用户选择安装模式:通过网络安装、下载后安装或者通过本地软件包缓存(安装时自动在本地目录下建立的软件包缓存)安装。如果是第一次安装 Cygwin,因为本地尚没有软件包缓存,当然只能选择从网络安装,d81d50817874?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

image

(3) 设置本地软件包缓存目录,默认为setup.exe 所处的目录,

d81d50817874?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

image

(4) 设置网络连接方式是否使用代理等,如图所示。默认会选择第一项:“直接网络连接”。如果一个团队有很多人要使用 Cygwin,架设一个能够提供软件包缓存的 HTTP 代理服务器会节省大量的网络带宽和大量的时间。

d81d50817874?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

image

(5) 选择一个 Cygwin 源,如图所示。如果在上一个步骤中选择使用 HTTP 代理服务器,就必须选择 HTTP 协议的 Cygwin 源。

d81d50817874?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

image

(6) 从所选的 Cygwin 源下载软件包索引文件,然后显示软件包管理器界面,我们要在这一步选择安装Git相关的软件包。默认安装的 Cygwin 没有安装 Git 软件包。如果在首次安装过程中忘记通过包管理器选择安装 Git 或其他相关软件包,可以在安装后再次运行 Cygwin 的安装程序 setup.exe 。当再次进入Cygwin 包管理器界面时,在搜索框中输入 git,这里我们需要安装下面几个软件,

git

git-completion: 提供 Git 命令的自动补齐功能。安装该软件包时会自动安装其所依赖的 bash-completion 软件包。

vim: Git 默认的编辑器。

openssh: SSH 客户端,为访问 SSH 协议的版本库提供支持。

cygcheck -c cygwin

d81d50817874?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

image

也就是说,在 Cygwin 中以路径 /cygdrive/c/Windows来访问Windows 下的 C:\Windows 目录。

设置Cygwin的Home目录

修改 Cygwin 启动的批处理文件(如:C:\cygwin\Cygwin.bat ),在批处理的开头添加如下的一行代码,就可以防止其他软件在 Windows 引入的 HOME 环境变量被带入到 Cygwin 中。

1

Set HOME=d:\cygwin\home

//

这个根据你自己的目录来设置

命令行补齐忽略文件名大小写

Windows 的文件系统忽略文件名的大小写,在 Cygwin 下最好对命令行补齐进行相关设置,以忽略大小写,这样使用起来更方便。编辑文件 ~/.inputrc ,在其中添加设置“set completion-ignore-case on”,或者取消已有的相关设置前面的井(#)号注释符。修改完毕后,再重新进入 Cygwin,这样就可以实现命令行补齐对文件名大小写的忽略。

Git配置

由于在windows平台下,所以可以禁止Git对文件权限的跟踪

1

git config --system core.fileMode

false

解决Git命令输出中文文件名的显示问题

1

git config --system core.quotepath

false

Git命令输出中开启颜色显示

1

git config --system color.ui

true

配置username和email

1

2

git config --global user.name

"Jim"

通过命令来查看Git设置

1

git config -l

可以得到如下的结果,

1

2

3

4

5

6

7

8

9

10

user.name=Jim

color.ui=

true

core.filemode=

false

core.quotepath=

false

core.repositoryformatversion=0

core.bare=

false

core.logallrefupdates=

true

core.ignorecase=

true

credential.helper=cache --timeout=3600

配置alias命令别名

1

2

3

4

5

6

7

git config --system

alias

.st status

git config --system

alias

.ci

"commit -s"

git config --system

alias

.co checkout

git config --system

alias

.br branch

git config --system

alias

.ll

"log --pretty=fuller --stat --graph --decorate"

git config --system

alias

.

ls

"log --pretty=oneline --graph --decorate"

git config --system

alias

.ss

"status -sb"

Git访问SSH 服务

这里的SSH还是指Cygwin里面的SSH,也就是OpenSSH。这块其实可以参考一下GitHub上的帮助页面https://help.github.com/articles/generating-ssh-keys

生成SSH密钥对

1

ssh

-keygen -t rsa -C

"jim@gmail.com"

你会看到如下的输出:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

Generating public

/private

rsa key pair.

Enter

file

in

which

to save the key (

/home/eason

.wu/.

ssh

/id_rsa

):

Created directory

'/home/eason.wu/.ssh'

.

Enter passphrase (empty

for

no passphrase):

Enter same passphrase again:

Your identification has been saved

in

/home/eason

.wu/.

ssh

/id_rsa

.

Your public key has been saved

in

/home/eason

.wu/.

ssh

/id_rsa

.pub.

The key fingerprint is:

58:7d:74:d9:d6:52:79:24:d7:18:e4:

dd

:bd:03:28:94 jim@gmail.com

The key's randomart image is:

+--[ RSA 2048]----+

| .. ..=BB|

| .E ..o+=O|

| .......o=|

| o .. . .|

| . S o |

| .|

| |

| |

| |

+-----------------+

Clone项目

d81d50817874?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

image

小结

利用Git来进行源代码管理是一个长期学习的过程,对于Git的理解也必须在不断的使用中体会。 总之, 每天进步一点

Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐