git 常用命令總結
git config --global user.name "Your Name"
git config --global user.email "email@example.com"
git config --global core.ignorecase false
git config --global core.autocrlf true
git config --global alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative"
git config --global http.proxy 'socks5://127.0.0.1:1080'
git config --global core.quotepath false //git status 中文名亂碼
git config --global gui.encoding utf-8
git config --global i18n.commitencoding utf-8
git config --global i18n.logoutputencoding utf-8
git config --global core.whitespace cr-at-eol //git diff ^M的消除
git config --global core.filemode false
git config core.filemode false //忽略文件模式的改變。比如從mac上拷貝一個git項目到windows上
git config --global branch.master.rebase true
ssh-keygen -t rsa -C "youremail@example.com"
ssh-keygen -R 192.168.3.10 (刪除信息改變的.ssh/known_hosts ip)
ssh -Vxx
ssh -Tv git@github.com
關聯github
git remote add origin xxx.git
git pull origin master
git push -u origin master
export GIT_TERMINAL_PROMPT=1
Switching remote URLs from HTTPS to SSH
git remote -v
git remote set-url origin git@github.com:xxx/xxx.git
git提示英文: 環境變量加入
export LESSCHARSET=utf-8
alias git='LANG=en_GB git'
git add . // git add -A // git add filename
git commit -m "..."
git pull origin master
git push origin master
git diff filename //查看工作區文件的改變
git diff --cached filename // 查看暫存區文件的改變
git diff commitid// 查看與commitid 之間的不同
git reset --hard commitid //回到 指定的commitid
git reset head filename //忽略 暫存區 指定文件的改變
git checkout . //忽略所有的 工作區 的文件改變
git checkout filename //忽略指定的 工作區 的文件改變
git tag
git tag v0.1.7
git tag -h
git tag -d v0.1.7
git push --tags
git push --tags -f
git clone設置代理
git config --global http.proxy http://127.0.0.1:1080
git config --global https.proxy https://127.0.0.1:1080
git config --global --unset http.proxy
git config --global --unset https.proxy
git config --global http.proxy 'socks5://127.0.0.1:1080'
git config --global https.proxy 'socks5://127.0.0.1:1080'
合并多個commit
git rebase -i hash_value //-i 的參數是不需要合并的 commit 的 hash 值,這里指的是第一條 commit

要合并 3f5380b, 4d5f824, dd74157 則執行 git rebase -i 0a23a25



pick 的意思是要會執行這個 commit
squash 的意思是這個 commit 會被合并到前一個commit
保留第一個為pick ,選擇后幾個commit 前的pick 改為s 或者 squash 保存
刪除多余的commit 信息 只保留一個 保存
git push -f //強制覆蓋遠程的commit
忽略已經被追蹤的git文件
git rm -r --cached .
git add .
git commit -m 'update .gitignore'
git status
git log
git branch -av
git checkout branchname //切換到指定分支
git commit --amend //修改最后一次未push的commit的內容
git stash list //查看stash
git stash pop //取出最近一次的stash
git stash // 把當前工作stash
git stash 版本號 // 跳到指定的stash
git stash drop 版本號 // 刪除指定的stash
git stash clear //刪除所有的stash
git reset --hard 失誤后恢復到之前的commit,查看commit記錄
git reflog


1.創建孤立(空)分支
使用git checkout -b命令創建的分支是有父節點的,這意味著新的分支包含了歷史提交,所以我們需要使用git checkout --orphan命令,創建孤立分支。
2.清除內容
使用git checkout --orphan 分支名創建的分支會把原分支的內容拷貝過來,因為要創建空分支,所以需要使用git rm -rf .來清除拷貝的內容。
如果空分支沒有任何文件被提交,使用git branch是看不到空分支,創建一個README.md文件來描述這個分支。提交后,再使用git branch就能看到創建的空分支img了。
3.使用branch來查看分支是否創建成功
git branch -a
4.提交到遠程分支
git push origin img
為php用戶添加git權限
// chdir("js");
// exec("git config --global user.name \"xxx\" > ../error.log 2>&1",$o1,$e1);
// echo `git config --global user.email \"xxx@xxx.com\"`;
git mergetool 配置(P4Merge)
https://cdist2.perforce.com/perforce/r19.2/bin.macosx1013x86_64/P4V.dmg
vi /usr/local/bin/extMerge
內容
#!/bin/sh
/Applications/p4merge.app/Contents/MacOS/p4merge $*
vi /usr/local/bin/extDiff
內容
#!/bin/sh
[ $# -eq 7 ] && /usr/local/bin/extMerge "$2" "$5"
sudo chmod +x /usr/local/bin/extMerge
sudo chmod +x /usr/local/bin/extDiff
git config --global merge.tool extMerge
git config --global mergetool.extMerge.cmd 'extMerge "$BASE" "$LOCAL" "$REMOTE" "$MERGED"'
git config --global mergetool.extMerge.trustExitCode false
git config --global diff.external extDiff
浙公網安備 33010602011771號