<name>
: 分支名
查看分支:git branch
功能 | 命令 |
---|---|
创建分支 | git branch <name> |
切换分支 | git checkout <name> |
创建+切换分支 | git checkout -b <name> |
合并某分支到当前分支 | git merge <name> |
删除分支 | git branch -d <name> |
查看分支 | git branch |
查看远程分支 | git branch -a |
查看当前分支最后一次修改的信息 | git show |
查看当前分支最后一次修改信息简化版 | git show --stat |
.
- 关于有时pull没有跟踪信息:
git pull
There is no tracking information for the current branch.(当前分支没有跟踪信息)
Please specify which branch you want to merge with.
See git-pull(1) for details.
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/<branch> c
原因:
这是说你当前的分支没有跟踪远程库的某个分支,也就是他们之间没有建立联系。
如果需要pull的话,需要我们自己为他们建立联系。
假如现在远程仓库有个分支a ,你本地有个分支叫做c ,但是远程没有c分支。
然后直接git pull
,就会出现这种情况。
解决方法:
现在是c分支
要和远程分支a建立联系
git branch --set-upstream-to=origin/a
git pull
.
新创建的分支如果push
时显示:
fatal: The current branch feature_v1.3.11_look-detail has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin <name>
那么就照着他说的执行git push --set-upstream origin <name>
这句就好了
需要注意的事情:
假如现在在分支A,然后修改A以后,直接切换到分支B,
有时会提示:Please commit your changes or stash them before you switch branches. Aborting
说名还没有commit 。
直接:
git add .
git commit
提交就行了
我还碰到过一种情况,就是没有commit也能切换
如果是这样的话,在A中修改的内容会带到B分支来。但其实不是真的带到B来了,再切换回A分支,提交一下,然后A带到B的内容就没了,B分支就恢复正常了。