1、
设置编辑默认vim:
git config中设置core.editor:
git config --global core.editor "vim"
2、
撤销提交:
git reset HEAD^ //撤销提交,文件还在。
git reset --soft HEAD^ //撤销提交,保持git add状态,文件还在。
git reset --hard HEAD^ //hard文件消失。
另外遇到git merge冲突,想退出merge;
git reset --hard HEAD
git revert HEAD //增量式撤销提交,新增commit log
3、
git clone下来的子仓库为空:
git submodule init
git submodule update
4、
branch:
git branch -vv //显示所有本地及远程仓关系
git remote -v //显示远程仓库url
新建branch并跟踪远端:
git checkout -b topic-4.11-dev origin/topic-kernel-4.11
push branch到远端:
$ git push origin test:master // 提交本地test分支作为远程的master分支
$ git push origin test:test // 提交本地test分支作为远程的test分支
$ git push origin HEAD:topic-kernel-4.11 //可以将这个branch 推到远端topic-kernel-4.11;解决push refs失败和already up to date问题
已有的分支跟踪:
$git branch --set-upstream-to=origin/<branchname> <branchname>
取消跟踪:
$git branch --unset-upstream origin/<branchname>
删除本地分支:
git branch -d testbranch
重命名本地分支:
git branch -m oldbranch newbranch
删除远程分支branchname:
方法1:
git branch -d -r origin/<branchname>
方法2:
git push origin :<branchname> //提交空对象到远程分支,等于删除
例:
$ git push origin :test // 提交到远程的test将被删除
push commit:
$ git push origin test //git push到远程指定分支
git remote update origin --prune //this will remove deleted remote branches locally
git push origin --delete <branch_name> //this will delete the remote branch. be careful, and check to ensure the branch has no value first
5、
新建tag
$ git tag -a v0.1.2 -m “0.1.2版本”
git branch newbranch v1.0 //根据tag建分支
git branch my2.1.3 v2.1.3 //以tag v2.1.3为start-point,创建新的本地分支branchname。
6、
patch:
比较两个分支同一个目录差别:
git diff branch1 branchnew drivers/net/ethernet/xxx > xxx.patch //比较branch1和branchnew 这两个分支drivers/net/ethernet/xxx 这个目录的差别
一般patch:
git diff > patch
git diff --cached > patch
git diff branchname --cached > patch
git apply --check patch //check patch
git apply patch //应用patch
7、
$ git rm test.txt //rm 'test.txt'
$ git commit -m "remove test.txt"
8、
git log:
git log --pretty=oneline 文件名
git show commitid
git show HEAD~N //查看某次提交
9、gitconfig
[user]
name = xxx
email = xxx@163.com
[sendemail]
smtpserver = smtp.163.com
smtpuser = xxx@163.com
smtppass = xxxxxx
smtpserverport =25
[http]
sslverify = false
设置编辑默认vim:
git config中设置core.editor:
git config --global core.editor "vim"
2、
撤销提交:
git reset HEAD^ //撤销提交,文件还在。
git reset --soft HEAD^ //撤销提交,保持git add状态,文件还在。
git reset --hard HEAD^ //hard文件消失。
另外遇到git merge冲突,想退出merge;
git reset --hard HEAD
git revert HEAD //增量式撤销提交,新增commit log
3、
git clone下来的子仓库为空:
git submodule init
git submodule update
4、
branch:
git branch -vv //显示所有本地及远程仓关系
git remote -v //显示远程仓库url
新建branch并跟踪远端:
git checkout -b topic-4.11-dev origin/topic-kernel-4.11
push branch到远端:
$ git push origin test:master // 提交本地test分支作为远程的master分支
$ git push origin test:test // 提交本地test分支作为远程的test分支
$ git push origin HEAD:topic-kernel-4.11 //可以将这个branch 推到远端topic-kernel-4.11;解决push refs失败和already up to date问题
已有的分支跟踪:
$git branch --set-upstream-to=origin/<branchname> <branchname>
取消跟踪:
$git branch --unset-upstream origin/<branchname>
删除本地分支:
git branch -d testbranch
重命名本地分支:
git branch -m oldbranch newbranch
删除远程分支branchname:
方法1:
git branch -d -r origin/<branchname>
方法2:
git push origin :<branchname> //提交空对象到远程分支,等于删除
例:
$ git push origin :test // 提交到远程的test将被删除
push commit:
$ git push origin test //git push到远程指定分支
git remote update origin --prune //this will remove deleted remote branches locally
git push origin --delete <branch_name> //this will delete the remote branch. be careful, and check to ensure the branch has no value first
5、
新建tag
$ git tag -a v0.1.2 -m “0.1.2版本”
git branch newbranch v1.0 //根据tag建分支
git branch my2.1.3 v2.1.3 //以tag v2.1.3为start-point,创建新的本地分支branchname。
6、
patch:
比较两个分支同一个目录差别:
git diff branch1 branchnew drivers/net/ethernet/xxx > xxx.patch //比较branch1和branchnew 这两个分支drivers/net/ethernet/xxx 这个目录的差别
一般patch:
git diff > patch
git diff --cached > patch
git diff branchname --cached > patch
git apply --check patch //check patch
git apply patch //应用patch
7、
$ git rm test.txt //rm 'test.txt'
$ git commit -m "remove test.txt"
8、
git log:
git log --pretty=oneline 文件名
git show commitid
git show HEAD~N //查看某次提交
9、gitconfig
[user]
name = xxx
email = xxx@163.com
[sendemail]
smtpserver = smtp.163.com
smtpuser = xxx@163.com
smtppass = xxxxxx
smtpserverport =25
[http]
sslverify = false