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 -t rsa -C "[email protected]" Generating public/private rsa key pair. Enter file in which to save the key (/c/Users/chenwei/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /c/Users/chenwei/.ssh/id_rsa. Your public key has been saved in /c/Users/chenwei/.ssh/id_rsa.pub. The key fingerprint is: SHA256:8qa01nxrfl+2KcmdpIUcMu9vtGEYobyIKTVJTZkxIak [email protected] The key‘s randomart image is: +---[RSA 2048]----+ | .+== | | o.+. . | | o . . . . | | E + = o | | o S . * = | | . = . . = * | | ooo o O *| | ..+o o .* Bo| | .o +oo .=+ | +----[SHA256]-----+ [email protected] MINGW32 ~ $
然后把生成的/c/Users/chenwei/.ssh/id_rsa.pub 拷贝到 github里面的<user>--<setting>--<SSH
and GPG keys>,添加到ssh key里面即可。
使用命令测试,如果出现下面成功,说明已经配置成功了。
$ ssh [email protected] PTY allocation request failed on channel 0 Hi woshiwei! You‘ve successfully authenticated, but GitHub does not provide shell access. Connection to github.com closed.
二 维护常见操作
2.1 克隆git库
#git clone xxxx cd login_main D:\chenwei\login_main>git clone https://github.com/woshiwei201/login_main.git Cloning into ‘login_main‘... remote: Counting objects: 3, done. remote: Total 3 (delta 0), reused 3 (delta 0), pack-reused 0 Unpacking objects: 100% (3/3), done. Checking connectivity... done.
2.2 更新提交代码
#git add xxxx 添加需要更新的文件 #git commit -m "first update" 提交代码到暂存区 #git remote add origin [email protected]:woshiwei201/login_main #git push -u origin master #同步到服务器
具体实例:
D:\chenwei\login_main\login_main>git add * D:\chenwei\login_main\login_main>git commit -m "add login_main" [master a872fab] add login_main 4 files changed, 127 insertions(+) create mode 100644 README.txt create mode 100644 login_main_v1.1.py create mode 100644 login_user.jpg create mode 100644 user_config.conf D:\chenwei\login_main\login_main>git remote add origin https://github.com/woshiw ei201/login_main.git fatal: remote origin already exists. D:\chenwei\login_main\login_main>git push -u origin master ounting objects: 6, done. Delta compression using up to 8 threads. Compressing objects: 100% (6/6), done. Writing objects: 100% (6/6), 88.18 KiB | 0 bytes/s, done. Total 6 (delta 0), reused 0 (delta 0) To https://github.com/woshiwei201/login_main.git eb8b592..a872fab master -> master Branch master set up to track remote branch master from origin.
#查看地址:
https://github.com/woshiwei201/login_main
2.3 删除文件
#git rm hello.md #输入想要删除的文件 #git status #查看当前状态 #git commit -m "no need file" #提交到暂存区 #git push origin master #同步到服务器
具体实例:
D:\chenwei\login_main\login_main>git status On branch master Your branch is up-to-date with ‘origin/master‘. Changes to be committed: (use "git reset HEAD <file>..." to unstage) deleted: hello.md D:\chenwei\login_main\login_main>git commit -m "no need file" [master 3950a7f] no need file 1 file changed, 1 deletion(-) delete mode 100644 hello.md D:\chenwei\login_main\login_main>git push origin master Counting objects: 2, done. Delta compression using up to 8 threads. Compressing objects: 100% (2/2), done. Writing objects: 100% (2/2), 218 bytes | 0 bytes/s, done. Total 2 (delta 1), reused 0 (delta 0) To https://github.com/woshiwei201/login_main.git af9dbc6..3950a7f master -> master D:\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 "[email protected]"
#查看配置信息
git config --list
3.2 git命令状态
#git 3个命令状态
git status
已修改 工作目录
已暂存 暂存区域 git add
已提交 git目录 commit
时间: 2024-10-27 09:25:27