2016-01-05 by 木易哥哥
一些命令
git clone 文件路径 //克隆文件
git commit -am ‘说明’ //提交代码
git push //上传代码
git pull //拉取代码
还原原来版本号
git log --> git reset --hard --> git 版本号
分支
git checkout -b 分支名 //创建分支和切换过去
git checkout 分支名 //切换分支
git branch //查看分支
合并分支
git checkout master --> git pull --> git pull origin 分支名 --> git commit -am '注释' --> git push
配置
产生SSH key
根据Github提供的help文档,具体过程如下
1 2 | $ cd ~/.ssh
# Checks to see if there is a directory named ".ssh" in your user directory
|
使用ssh-keygen产生新的key
1 2 3 4 | $ ssh-keygen -t rsa -C "your_email@example.com"
# Creates a new ssh key using the provided email
Generating public/private rsa key pair.
Enter file in which to save the key (/home/you/.ssh/id_rsa):
|
使用默认的文件名直接enter, 按提示输入密码(如果不提供密码,SSH将无密码连接,如果private key泄露可能会有安全问题)
1 2 | Enter passphrase (empty for no passphrase): [Type a passphrase]
Enter same passphrase again: [Type passphrase again]
|
密匙产生成功
1 2 3 4 | Your identification has been saved in /home/you/.ssh/id_rsa.
Your public key has been saved in /home/you/.ssh/id_rsa.pub.
The key fingerprint is:
01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db your_email@example.com
|
如果希望保留生产服务器上所做的改动,仅仅并入新配置项, 处理方法如下:
git stash
git pull
git stash pop
然后可以使用git diff -w +文件名 来确认代码自动合并的情况.
参考:http://www.cnblogs.com/wangkongming/p/4158664.html
使用git创建一个项目的过程
1.先在git dashboard 新建个工程
2.git clone 新建工程地址
3.cd 该工程目录
4.$ git init //初始化
5.$ touch README
6.$ git add README //更新README文件
7.$ git commit -m ‘first commit’ //提交更新
8.$ git push -u origin master //将本地项目更新到github项目上去
如果以上提交不成功,需连接服务器删除hooks,步骤如下
1.ssh root@112.74.112.54
2.cd /mnt/data/gitlab/apps/gitlab/repositories
3.ll
4.cd 自己的git名,如cd yangxiaohua/
5.cd uyes_wbs_android.git/
6. rm hooks
统计代码行数
1、打开终端
2、cd 进入项目根目录
3、输入命令 find . "(" -name "*.m" -or -name "*.mm" -or -name "*.cpp" -or -name "*.h" -or -name "*.rss" ")" -print | xargs wc -l
4、回车
出结果。
在 Mac 上用 SourceTree 克隆 svn 的时候, 出现了 warning: templates not found /usr/local/git/share/git-core/templates 警告,导致克隆失败. 怎么办呢.
在终端输入
sudo mkdir /usr/local/git
sudo mkdir /usr/local/git/share
sudo mkdir /usr/local/git/share/git-core
sudo mkdir /usr/local/git/share/git-core/templates
sudo chmod -R 755 /usr/local/git/share/git-core/templates
前四条创建目录,最后一条给修改目录添加权限. 注意 sudo 创建目录需要输入当前 Mac 用户的密码
再重新克隆, 云消雨散.