g一 git 安装配置

1.1 安装

由于大部分工作是在windows下,故下载gitwindows版本,注意要区别32位和64位

使用的是git gui

安装软件,默认点击下一步:

Git-2.7.2-32-bit_setup.1457942412.exe


1.2 生成git bash内容

生成秘钥:

$ssh-keygen.exe-trsa-C"woshiwei@gmail.com"Generatingpublic/privatersakeypair.Enterfileinwhichtosavethekey(/c/Users/chenwei/.ssh/id_rsa):Enterpassphrase(emptyfornopassphrase):Entersamepassphraseagain:Youridentificationhasbeensavedin/c/Users/chenwei/.ssh/id_rsa.Yourpublickeyhasbeensavedin/c/Users/chenwei/.ssh/id_rsa.pub.Thekeyfingerprintis:SHA256:8qa01nxrfl+2KcmdpIUcMu9vtGEYobyI×××JTZkxIakwoshiwei@gmail.comThekey'srandomartp_w_picpathis:+---[RSA2048]----+|.+==||o.+..||o....||E+=o||oS.*=||.=..=*||ooooO*||..+oo.*Bo||.o+oo.=+|+----[SHA256]-----+chenwei@vbearMINGW32~$

然后把生成的/c/Users/chenwei/.ssh/id_rsa.pub 拷贝到 github里面的<user>--<setting>--<SSHand GPG keys>,添加到ssh key里面即可。

使用命令测试,如果出现下面成功,说明已经配置成功了。

$sshgit@github.comPTYallocationrequestfailedonchannel0Hiwoshiwei!You'vesuccessfullyauthenticated,butGitHubdoesnotprovideshellaccess.Connectiontogithub.comclosed.


二 维护常见操作

2.1 克隆git库

#gitclonexxxxcdlogin_mainD:\chenwei\login_main>gitclonehttps://github.com/woshiwei201/login_main.gitCloninginto'login_main'...remote:Countingobjects:3,done.remote:Total3(delta0),reused3(delta0),pack-reused0Unpackingobjects:100%(3/3),done.Checkingconnectivity...done.


2.2 更新提交代码

#gitaddxxxx添加需要更新的文件#gitcommit-m"firstupdate"提交代码到暂存区#gitremoteaddorigingit@github:woshiwei201/login_main#gitpush-uoriginmaster#同步到服务器


具体实例:

D:\chenwei\login_main\login_main>gitadd*D:\chenwei\login_main\login_main>gitcommit-m"addlogin_main"[mastera872fab]addlogin_main4fileschanged,127insertions(+)createmode100644README.txtcreatemode100644login_main_v1.1.pycreatemode100644login_user.jpgcreatemode100644user_config.confD:\chenwei\login_main\login_main>gitremoteaddoriginhttps://github.com/woshiwei201/login_main.gitfatal:remoteoriginalreadyexists.D:\chenwei\login_main\login_main>gitpush-uoriginmasterountingobjects:6,done.Deltacompressionusingupto8threads.Compressingobjects:100%(6/6),done.Writingobjects:100%(6/6),88.18KiB|0bytes/s,done.Total6(delta0),reused0(delta0)Tohttps://github.com/woshiwei201/login_main.giteb8b592..a872fabmaster->masterBranchmastersetuptotrackremotebranchmasterfromorigin.

#查看地址:


https://github.com/woshiwei201/login_main


2.3 删除文件

#gitrmhello.md#输入想要删除的文件#gitstatus#查看当前状态#gitcommit-m"noneedfile"#提交到暂存区#gitpushoriginmaster#同步到服务器


具体实例:

D:\chenwei\login_main\login_main>gitstatusOnbranchmasterYourbranchisup-to-datewith'origin/master'.Changestobecommitted:(use"gitresetHEAD<file>..."tounstage)deleted:hello.mdD:\chenwei\login_main\login_main>gitcommit-m"noneedfile"[master3950a7f]noneedfile1filechanged,1deletion(-)deletemode100644hello.mdD:\chenwei\login_main\login_main>gitpushoriginmasterCountingobjects:2,done.Deltacompressionusingupto8threads.Compressingobjects:100%(2/2),done.Writingobjects:100%(2/2),218bytes|0bytes/s,done.Total2(delta1),reused0(delta0)Tohttps://github.com/woshiwei201/login_main.gitaf9dbc6..3950a7fmaster->masterD:\chenwei\login_main\login_main>#登录界面验证https://github.com/woshiwei201/login_main


2.4 更新代码到本地



三 常见的配置信息

3.1 全局配置信息

#配置全局用户名参数

git config --global user.name "username"


#配置全局电子邮件地址

git config --global user.email "test@gamil.com"


#查看配置信息

git config --list


3.2 git命令状态

#git 3个命令状态

git status

已修改 工作目录

已暂存 暂存区域 git add

已提交 git目录 commit