公钥和私钥(过程略)
- 生成公钥
- 将公钥添加到git设置里面
- 通过git clone 克隆远程的分支下来(注意当前目录必须为空)
- 删除当前.git文件就相当于与远程仓库断开连接
# 克隆分支的命令
$ git clone <版本库的网址> <本地目录名>
$ git clone https://github.com/spareribs/scrapy-examples.git
用户配置
查看用户配置
git config --list
全局设置
$ git config --global user.name ****
$ git config --global user.email ****
代码仓库git设置
# 进入对应的目录,然后设置用户名和邮箱
$ cd git-repository/
$ git config user.name ****
$ git config user.email ****
# 查看代码仓库目录配置文件
$ cat .git/config
远程分支develop管理
$ git checkout -b develop
$ git branch -a
$ git merge puppet/develop
单个文件提交
# 查看状态
$ git status
# 将文件添加到暂存区
$ git add test.py
# 把暂存区的所有内容提交到当前分支并加入提交信息
$ git commit test.py -m "Just for a test"
与远程同步,push是提交,pull是拉取
$ git push <远程计算机名> <版本库的网址> <本地目录名>
$ git push puppet develop:develop
$ git pull puppet develop:develop
设置跟踪,直接使用git pull即可
$ git branch --set-upstream master origin/next
上面命令提示被弃用
建议使用track或者--set-upstream-to
$ git branch -u puppet/develop
$ git branch -vv(两个v),就能够看到本地分支跟踪的远程分支
设置不需要检测的文件
修改exclude文件
$ vi .git/info/exclude
*.*.bak
*.pyc
test_*
版本回退(删除记录型)
代码如下:
git log
git reset --soft ${commit-id}
git stash
git push -f
详解如下:
# 第1行:git log 查看提交历史,然后找到要回滚的版本。
commit 84686b426c3a8a3d569ae56b6788278c10b27e5b
Author: JeffLi1993 <qiangqiangli1993@gmail.com>
Date: Fri Apr 8 19:11:32 2016 +0800
我删除了老板的东西
commit 72bd6304c3c6e1cb7034114db1dd1b8376a6283a
Author: JeffLi1993 <qiangqiangli1993@gmail.com>
Date: Fri Apr 8 19:05:23 2016 +0800
add A.txt
# 我们想要回滚到的版本就是:72bd6304c3c6e1cb7034114db1dd1b8376a6283a
# 第2行,输入对应版本即可:
git reset --soft 72bd6304c3c6e1cb7034114db1dd1b8376a6283a
# 撤销到某个版本之前,之前的修改退回到暂存区(不懂看漂亮的图哦~)。
# soft 和 hard参数的区别就是,hard修改记录都没了,soft则会保留修改记录。
# 第3行:暂存为了安全起见。
# git stash来个安全快照
# 第4行,覆盖 -f
git push -f
将本地master push 到远程版本库中, -f 强制覆盖。