Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1270617
  • 博文数量: 482
  • 博客积分: 13297
  • 博客等级: 上将
  • 技术积分: 2890
  • 用 户 组: 普通用户
  • 注册时间: 2009-10-12 16:25
文章分类

全部博文(482)

文章存档

2012年(9)

2011年(407)

2010年(66)

分类: LINUX

2011-09-20 17:05:42

GIT下载

TortoiseGit下载

配置
  1. 生成keygen ssh-keygen -t rsa -C "email@email.com" 然后复制~/.ssh/id_rsa.pub的内容至,添加新的公钥,标题任意,公钥的内容为id_rsa.pub的内容
  2. 为当前版本库添加用户信息 git config --global user.name "7color" git config --global user.email email@email.com
  3. 创建版本库目录 mkdir 7color.github.com
  4. 切换至版本库目录 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 git remote add 7color(origin) git@github.com:xixer/7color.github.com.git
  10. 从7color标记(指定)的remote(远程主机)获取最新的版本到本地,并自动进行merge到本地当前分支上(fetch+merge) git pull 7color master
  11. 提交本地master分支的所有的修改至7color标记(指向)的remote(远程主机)的master分支 git push 7color master
其它命令
  1. 查看版本库状态: git status
  2. 查看版本纪录(-p 查看每个版本的改动纪录): git log
  3. 查看自上次提交以来发生什么改动: git diff
  4. 为某一版本创建版本标签: git tag (版本标签存储在.git/refs/tags/目录)
  5. 回溯到历史版本(--soft 回溯到已提交到索引但未提交到版本库的状态,--hard 将文件内容也一同回溯,--mixed 默认选项): git reset
    • git reset 回溯到git add之前的状态
    • git reset --soft回溯到git add之后的状态
  6. 分支:
    • 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 删除远程分支
  7. 还原已提交的修改
    • git revert HEAD 还原最近一次提交的修改
    • git revert commit-id 还原指定版本的修改
  8. 创建一个镜像版本库:
    • git clone 原始版本库路径 镜像版本库路径(local)
    • git fetch origin 更新 origin 分支。如果 origin 分支不是最新的原始版本库,会产生错误的补丁文件(不会自动merge,仅下载 & 更新索引)
    • git rebase origin 将工作迁移到最新原始版本库基础上
  9. git pull 从协作者那里获取更新, 并自动merge到本地的当前分支上(fetch+merge)
  10. echo "test">.gitignore 增加到忽略列表
  11. 查看帮助 git help gitignore,帮助在线文档: 安装目录/doc/git/html/gitignore.html
  12. 删除当前文件夹中的版本库(删除.git目录即可): rm -rf .git
  13. git init 初始化后,会在.git/目录下创建一个版本库,其中.git/config为配置文件
  14. 使用全局用户信息,在~/.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 完
资源链接

====

阅读(1106) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~