【ZZ】Git安装与配置

3配置
 1.生成keygen 
 
ssh-keygen -t rsa -C "email@email.com"
而后复制~/.ssh/id_rsa.pub的内容至github公钥,添加新的公钥,标题任意,公钥的内容为id_rsa.pub的内容
 2.为当前版本库添加用户信息 


git config --global user.name "7color"
git config --global user.email email@email.com

3.建立版本库目录 

mkdir 7color.github.com
 

4.切换至版本库目录 html

cd 7color.github.com

5.初始化版本库


git init

6.新建文件README
touch README
 
7.将文件提交到 git索引(空格分隔文件名, add . 提交全部)
git add README
 
8.提交版本库,并添加备注(-m 添加备注,无参数 调用系统编辑器添加备注,-a 省略add,一次性提交索引与提交版本库,--amend 调整以前的commit)

git commit -m "first commit"
git show #显示最后一次commit修改的内容
 

9.建立远程主机的标记7color python

git remote add 7color(origin) git@github.com:xixer/7color.github.com.git
 

10.从7color标记(指定)的remote(远程主机)获取最新的版本到本地,并自动进行merge到本地当前分支上(fetch+merge) linux

git pull 7color master

11.提交本地master分支的全部的修改至7color标记(指向)的remote(远程主机)的master分支 
git push 7color master
 
其它命令
查看版本库状态: git status
查看版本纪录(-p 查看每一个版本的改动纪录): git log
查看自上次提交以来发生什么改动: git diff
为某一版本建立版本标签: git tag (版本标签存储在.git/refs/tags/目录)
回溯到历史版本(--soft 回溯到已提交到索引但未提交到版本库的状态,--hard 将文件内容也一同回溯,--mixed 默认选项): git reset
git reset 回溯到git add以前的状态
git reset --soft回溯到git add以后的状态
分支:
git branch 查看分支(-a 查看全部分支)
git branch 分支名称 新建分支
git checkout 切换到指定分支(-b 建立分支并切换分支)
git checkout 文件名 恢复某个已修改的文件#撤消未提交的修改
git branch -D 分支名称 删除分支(-D强行删除分支;-d只有分支内容被合并后才能删除)
git merge 分支名称 合并指定分支到当前分支
git push git@github.com:ACCOUNT/SPACE.git :heads/BRANCH 删除远程分支
还原已提交的修改
git revert HEAD 还原最近一次提交的修改
git revert commit-id 还原指定版本的修改
建立一个镜像版本库:
git clone 原始版本库路径 镜像版本库路径(local)
git fetch origin 更新 origin 分支。若是 origin 分支不是最新的原始版本库,会产生错误的补丁文件(不会自动merge,仅下载 & 更新索引)
git rebase origin 将工做迁移到最新原始版本库基础上
git pull 从协做者那里获取更新, 并自动merge到本地的当前分支上(fetch+merge)
echo "test">.gitignore 增长到忽略列表
查看帮助 git help gitignore,帮助在线文档: 安装目录/doc/git/html/gitignore.html
删除当前文件夹中的版本库(删除.git目录便可): rm -rf .git
git init 初始化后,会在.git/目录下建立一个版本库,其中.git/config为配置文件
使用全局用户信息,在~/.gitconfig中写入:
 
[user]
name = 7color
email = email@email.com
*或者*
git config --global user.name "7color"
git config --global user.email email@email.com



错误描述
"remote:error: refushing to delete the current branch:refs/heads/BRANCH to git@github.com:ACCOUNT/SPACE.git ![remote rejected] BRANCH (deletion of the current branch prohibited) error: failed to push some refs to 'git@github.com:ACCOUNT/SPACE.git'"
解决方法: 在github.com的管理员页面,切换当前分支,再次运行删除分支命令便可.
 
"Permission denied to SPACE.git denied to ACCOUNT"
 
解决方法: 
ssh-keygen -t rsa -C "email@email.com" 
复制~/.ssh/id_rsa.pub内容 
打开githu.com->帐户设置->SSH公钥->添加新的公钥,保存 
ssh-add 完



"FATAL ERROR: Disconnected: No supported authentication methods available.fatal: The remote end hung up unexpectedly."
解决方法: 
ssh -v git@github.com,若是出现successfully authenticated即表示公钥配置成功. 
若是你同时安装了Git & TortoiseGit,可使用echo $GIT_SSH查看ssh链接方式.
使用其中一种方式,declare GIT_SSH="D:\Git\bin\sh.exe",再次echo $GIT_SSH查看是否修改为功.接着再次push试试,应该就能够了.
若是想一劳永逸的作法是个人电脑->高级->环境变量中添加/修改GIT_SSH的值.而后重启电脑.

支持Git & TortoiseGit 共存
解决方法: 使用puttygen.exe生成的private key复制到github.com的共钥中便可. 
"To git@github.com:7color/7color.github.com.git ! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:7color/7color.github.com.git'
To prevent you from losing history, non-fast-forward updates were rejected Merge the remote changes (e.g. 'git pull') before pushing again.

See the 'Note about fast-forwards' section of 'git push --help' for details."
解决方法: 
git pull 7color master 
编辑冲突 
git commit -am "resolve conflict" 
git push 7color master 完

资源连接
http://v.youku.com/v_playlist/f5227985o1p0.html 视频 
http://wangcongming.info/category/geek-tweak/ git-系列(推荐) 
http://roclinux.cn/?p=2115#more-2115 看日记学git 
http://wenku.baidu.com/search?word=git&lm=0&od=0 百度文库 
http://git-scm.com/ 
http://hi.baidu.com/felixwang/blog/item/7ce2cf1b2fccf7fdaf51338b.html 使用public/private key让putty(ssh)自动登陆 
http://www.kudelabs.com/2008/09/24/mysmgit-%E4%B9%8Bgit-on-windows%E5%BF%AB%E9%80%9F%E4%B8%8A%E6%89%8B mysmGit 之Git on Windows快速上手 
http://www.ha97.com/book/OpenSource_Guide/ch28s05.html git命令入门 
http://help.github.com/msysgit-key-setup/ ssh keygen 
http://pages.github.com/ git pages 
http://eshilin.blog.163.com/blog/static/13288033020106610250138/ Git startup 
http://eshilin.blog.163.com/blog/static/132880330201066102650433/ Git branch 
http://eshilin.blog.163.com/blog/static/132880330201062991718683/ Git hook book 
http://rongjih.blog.163.com/blog/static/335744612010619111042465/ TortoiseGit密钥的配置
相关文章
相关标签/搜索