Git

從 qingwei personal wiki
於 2018年9月28日 (五) 02:41 由 Qingwei (對話 | 貢獻) 所做的修訂 (常用命令)
跳到: 導覽搜尋

SSH key生成

windows

#生成ssh key的命令
qingwyan@QINGWYAN-FTCEW MINGW64 ~/Desktop/git
$ ssh-keygen -t rsa -C "qingwyan@cisco.com"

# 进入到生成的ssh key目录
qingwyan@QINGWYAN-FTCEW MINGW64 ~/Desktop/git
$ cd /c/Users/qingwyan/.ssh

# copy到剪切板
qingwyan@QINGWYAN-FTCEW MINGW64 ~/.ssh
$ clip < id_rsa.pub

常見錯誤

git pull/fetch: unable to update local ref

  • 現象
[qingwyan@crdc-sdn-ucs2 rpd-service-manager]$ git fetch

error: there are still refs under 'refs/remotes/origin/bugfix/haofan'
From ssh://bitbucket-eng-sjc1.cisco.com:7999/cmtsorch/rpd-service-manager
 ! [new branch]      bugfix/haofan -> origin/bugfix/haofan  (unable to update local ref)
  • 解決方案:刪除文件
rm -rf .git/refs/remotes/origin/bugfix/haofan
  • 新的問題
[qingwyan@crdc-sdn-ucs2 rpd-service-manager]$ git fetch

error: 'refs/remotes/origin/bugfix/haofan/device-key' exists; cannot create 'refs/remotes/origin/bugfix/haofan'
From ssh://bitbucket-eng-sjc1.cisco.com:7999/cmtsorch/rpd-service-manager
 ! [new branch]      bugfix/haofan -> origin/bugfix/haofan  (unable to update local ref)
error: some local refs could not be updated; try running
 'git remote prune origin' to remove any old, conflicting branches
  • 按提示刪除
git remote prune origin

常用命令

當前分支commit數量

# 获取当前分支的 commit 数量
git rev-list HEAD --count

# 比上面的少点 ---上面的会有重复的,少了些重复的, >< 我也不知道。。。
git rev-list HEAD --count --first-parent

回滾到上一個commit

git reset --hard 0cd5c0e54528c9ff07f7e0df50f800f05c5be8e4

git diff忽略^M

git config --global core.whitespace cr-at-eol