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

 要合并 f4c55ea 和 14d6c5e 则执行 git rebase -i df13a45

pick 的意思是要会执行这个 commit
squash 的意思是这个 commit 会被合并到前一个commit
选择一个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

posted @ 2017-08-16 14:48  boybai  阅读(690)  评论(0编辑  收藏  举报