[color=red][b]git ssk clone init [/b][/color]
[img]http://dl2.iteye.com/upload/attachment/0126/3247/ca81c94a-3dab-3a2c-ab05-c5a9b699d6e1.png[/img]
[img]http://dl2.iteye.com/upload/attachment/0126/3249/85cee2d5-d37e-3392-8dcc-40bee70a9e06.png[/img]
[color=red][b]git remote http(s)方式如何自动记住密码[/b][/color]
[color=red][b]git 分支的使用[/b][/color]
[color=red][b]git 标签的使用[/b][/color]
ssh-keygen -t rsa -C "xxxxx@xxxxx.com"
cat ~/.ssh/id_rsa.pub
网页中添加 ssh key
然后测试 ssk 是否生效
ssh -T git@git.oschina.net
Welcome to Git@OSC, yourname!
git help
http://git.mydoc.io/?t=154712
http://www.liaoxuefeng.com/
查看用户名和邮箱地址:
$ git config user.name
$ git config user.email
修改用户名和邮箱地址:
$ git config --global user.name "username"
$ git config --global user.email "email"
克隆
git clone git|http 项目地址
上传一个项目
初始化 git
git init
touch .gitignore
vim .gitignore
git add . //添加到索引
git rm -r --cache .idea //删除索引
git commit -m "init"
git reset HEAD filename 撤销提交
git update-index --assume-unchanged filename 强制忽略某个文件
--关联远程地址
git remote add origin ...git
--删除远程主机地址
git remote rm origin
--pull 忽略没有关系的历史
git pull origin master --allow-unrelated-histories
git push -u origin master 提交代码到远程 master分支上
--------bug--------------
windows中的换行符为 CRLF, 而在Linux下的换行符为LF,所以在执行add . 时出现提示,解决办法:
[plain] view plain copy 在CODE上查看代码片派生到我的代码片
$ rm -rf .git // 删除.git
$ git config --global core.autocrlf false //禁用自动转换
然后重新执行:
[plain] view plain copy 在CODE上查看代码片派生到我的代码片
$ git init
$ git add .
rm -rf .git 删除 git 文件
[img]http://dl2.iteye.com/upload/attachment/0126/3247/ca81c94a-3dab-3a2c-ab05-c5a9b699d6e1.png[/img]
[img]http://dl2.iteye.com/upload/attachment/0126/3249/85cee2d5-d37e-3392-8dcc-40bee70a9e06.png[/img]
[color=red][b]git remote http(s)方式如何自动记住密码[/b][/color]
https方式每次都要输入密码,按照如下设置即可输入一次就不用再手输入密码的困扰而且又享受https带来的极速
按照以下设置记住密码十五分钟:
git config --global credential.helper cache
如果你想自定义记住的时间,可以这样:
git config credential.helper 'cache --timeout=3600' //这里记住的是一个小时,如需其
他时间,请修改3600为你想修改的时间,单位是秒
你也可以设置长期记住密码:
git config --global credential.helper store
或修改仓库的地址带上你的账号密码
http://yourname:password@git.oschina.net/name/project.git //注意,码云平台同时支持个性地址与邮箱,当使用邮箱时,请对@符号使用%40替换
如果你原本使用的ssh地址想更换成http(s)地址,可以执行以下命令:
//删除原本的ssh仓库地址
git remote rm origin //origin 代表你原本ssh地址的仓库的别名
//新增http地址的仓库
git remote add origin http://git.oschina.net/username/project.git
//修改远程仓库的名字
git remote rename origin org
[color=red][b]git 分支的使用[/b][/color]
--- 查看某个分支从哪个分支迁移出来
git reflog --date=local | grep dev-report-v1.4.1 |tail -n 1
创建分支
git checkout dev
显示分支名字
git branch -r|-a|-v
切换分支
git checkout origin dev
--合并分支
git merge dev
--分支创建 与合并
git checkout -b dev //luobing //切换 并新建一个分支 luobing
git push (-u) origin dev //push 本地dev 分支 到 远程分支
git branch (-u | --set-upstream-to=origin/dev )
origin/dev //默认关联本地 dev
删除分支
git branch -d dev // 删除本地分支
git push origin --delete dec_caoyw //删除远程分支
git branch -m dec_caoyw dev_caoyw //修改本地分支名称
恢复删除的分支 先 查日志 找到 commitid 然后 git branch 新分支找回
git log -g
commit 3eac14d05bc1264cda54a7c21f04c3892f32406a
Reflog: HEAD@{1} (fdipzone <fdipzone@sina.com>)
Reflog message: commit: add test.txt
Author: fdipzone <fdipzone@sina.com>
Date: Sun Jan 31 22:26:33 2016 +0800
git branch recover_branch_abc 3eac14d05bc1264cda54a7c21f04c3892f32406a
---fetch
git fetch origin dev:dev
git diff dev
git merge dev
--pull
git pull origin dev
[color=red][b]git 标签的使用[/b][/color]
新增标签
git log --oneline 查看日志
git tag -a v0.1
i 输入 标签备注 一般为 commit 前7位
也可以
git tag -a v0.2 -m "v0.2 version bug fixed"
提交 标签到远程仓库
git push origin --tags
git pull origin v0.1
显示标签信息
git show v0.1
切换标签
git checkout v0.1
列出标签
git tag
删除本地tag
git tag -d tagname
删除远程tag
git push origin :tagname
分支合并错误 然后 回滚
在GIT中创建一个空分支
git checkout --orphan doc
然后合并代码
git chekcout --orphan test1.2.0.6.1
允许提交 没有关联的历史记录
git merge test1.2.0.6 --allow-unrelated-histories
push 远程分支
git push org test1.2.0.6.1
git rebase test1.2.0.6 回把这个分支删除
git cherry-pick <commit id> 如何把已经提交的commit, 从一个分支放到另一个分支
git reset --hard commitId
git revert
git diff test1.2.0.6 test1.2.2.0.6.1 --cached
git diff test1.2.0.6 test1.2.2.0.6.1 --staged
git add .
git rm -rf --cache .filename
如果要是 提交了以后,可以使用 git revert
还原已经提交的修改
此次操作之前和之后的commit和history都会保留,并且把这次撤销作为一次最新的提交
git revert HEAD 撤销前一次 commit
git revert HEAD^ 撤销前前一次 commit
git revert commit-id (撤销指定的版本,撤销也会作为一次提交进行保存)
git revert是提交一个新的版本,将需要revert的版本的内容再反向修改回去,版本会递增,不影响之前提交的内容
git merge –no-ff 可以保存你之前的分支历史。能够更好的查看 merge历史,以及branch 状态。
git merge 则不会显示 feature,只保留单条分支记录。