工具程序员

常用Git 命令清单

2016-01-20  本文已影响263人  沪上最强亚巴顿
  1. 弄乱了本地分支, 想回退到上次[git pull] 之后.
    - git reset --hard origin/master # You will need to be comfortable doing this!
    - git reset HEAD~1
  2. 已经开始进行代码修改, 但是发现在不想变更的分支上.
git checkout -b new_branch_name  # just create a new branch
git add .                      # add the changes files
git commit -m"your message"    # and commit them
  1. 弄乱了一个文件, 想回退到该文件上次[git pull]之后.
    git checkout your/directories/filename
  2. 做了本地修改, 当执行[git rebase]/[git reset] 时不想丢失这些本地修改.
    手动拷贝整个目录
  3. rebasing 过程中弄乱了.
    git rebase --abort # To abandon interactive rebase and merge issues
  4. 在[push] 之前修改commit 信息.
    git commit --amend
  5. 退出[git log] 的结果显示
    press [q]
  6. 在工程目录下删除git 相关的信息.
    rm -rf .git
  7. 撤销一个已发布的commit.
    git revert --no-edit HEAD22
  8. 添加远程url.
    git init
    git remote add origin
  9. 添加private key.
    cd ~/.ssh
    ssh-keygen -t rsa -C ‘xxx@gmail.com'
  10. 回退到某个commit.
    git reset --hard <tag/branch/commit id>
    git push <reponame> -f
  11. 忽略和恢复追踪文件的变化
    git update-index --assume-unchanged file
    git update-index --no-assume-unchanged [<file> ...]
上一篇下一篇

猜你喜欢

热点阅读