1.查看项目的分支(包括远程分支和本地分支)
git branch -a
2.查看本地分支
git branch
3.删除本地分支
git branch -d <BranchName>
*<BranchName>本地分支的名字
4.删除远程分支
git push origin --delete <BranchName>
*<BranchName>远程分支的名字
5.创建本地分支,并切换到新创建的分支下
git checkout -b <BranchName> <origin BranchName>
*<BranchName> 本地分支的名字 <origin BranchName>远程分支的名字
6.切换本地分支
git checkout <BranchName>
*<BranchName>本地分支的名字
7.推送本地分支local_branch到远程分支 remote_branch并建立关联关系
a.远程已有remote_branch分支并且已经关联本地分支local_branch且本地已经切换到local_branch
git push
b.远程已有remote_branch分支但未关联本地分支local_branch且本地已经切换到local_branch
git push -u origin/remote_branch
c.远程没有有remote_branch分支并,本地已经切换到local_branch
git push origin local_branch:remote_branch
8.本地分支的文件添加到远程分支
git push --set origin remote_branch
适用于本地建立分支,远程没有分支,就是第七条的c的情况。第一次提交文件,需要这么做。
9.git放弃所有本地修改
git checkout . #本地所有修改的,没有提交的,都返回到原来的状态
git stash #把所有没有提交的修改暂存到stash里面。可用git stash pop 恢复。
git reset --hard HASH #返回到某个借点,不保留修改。
git reset --soft HASH #返回到某个节点,保留修改。
10.查看本地分支和远程分支的跟踪关系。
git branch -vv
11.dev分支merge到master
# 检出到dev分支
git checkout dev
# 拉取dev最新代码到当前文件夹
git pull
# 检出到master分支
git checkout master
# 将dev分支合并到master
git merge dev
# 将本地的master分支推送到origin主机
git push -u origin master
12.git cherry 合并某个commit
找到本地列表中,尚未推送到远程的提交。
git cherry -v 可以显示出提交的注释信息。
13.git cherry-pick <commit id>
参考自:链接
14.git stash save "reduce signature"
把不想提交的修改,暂存到堆栈区。
git stash list
查看当前stash中的内容
git stash pop
将当前stash中的内容弹出,并应用到当前分支对应的工作目录上。
参考自:https://blog.csdn.net/stone_yw/article/details/80795669
15.git remote show origin
可以查看远程库的一些信息,及与本地分支的信息。有时候可能遇到如下情况
这时红框内分支在远程库已经不存在了(你之前从远程库拉取过,可能之后被其他人删除了,你用 git branch -a 也是不能看出它们是否已被删除的),这时候我们可以删除本地库中这些相比较远程库中已经不存在的分支:
git remote prune origin
16.版本回退。
1、找到你误提交之前的版本号
2、git revert -n 版本号
3、git commit -m xxxx 提交
4、git push 推送到远程
OK,版本还原了,通知其他人更新一下代码吧
17.查看分支的创建时间
git reflog show --date=iso <branch name>
mac下git log退出方法:英文状态下按Q。