Git常用命令

查看分支
git branch       //查看本地分支
git branch -r   //查看远程分支


创建分支
git branch local_feature01   创建分支local_feature01      


git checkout local_feature01  // 切换到分支 local_feature01上面

创建并切换分支
git checkout -b local_feature02 // 创建分支 local_feature02,并切换到分支 local_feature02上面

推送新分支到远程
git push origin local_feature02 

--拉取远程仓库中的最新内容到本地分支

 切换到目标分支
 git checkout target-branch
 拉取远程仓库中的最新内容到本地分支
 git pull origin target-branch

合并分支到当前分支
git merge local_feature01   // 将分支 local_feature01 合并到当前分支


删除本地分支
git branch -d local_feature01     // 删除分支 local_feature01

删除远程分支
git branch -r -d origin/branch-name
git push origin :branch-name 

git push origin -d test //这个时候,因为本地没有这个分支,导致删除失败
git push origin :test //采取更新的方式,删除远程分支


分支重命名
git branch -m test newtest //先重命名本地分支




回滚
使用git reset命令将分支回退到上一个提交。有三种模式可以使用:--soft,--mixed,--hard。
--soft:回退到某个版本,保留工作目录和暂存区。
--mixed:回退到某个版本,保留工作目录,但是不保留暂存区。
--hard:回退到某个版本,不保留工作目录和暂存区的更改。git reset HEAD~1 //回滚刚才提交的那版

git reset --soft   -1    //默认回滚到上一个版本
 

  

posted @ 2024-05-16 14:53  闲云野鹤古刹  阅读(2)  评论(0编辑  收藏  举报