git操作命令

git clone https://github.com/xxx/xxx.git // 克隆代码

git branch   // 查看本地分支
git branch –a  // 显示本地、服务器所有分支
git branch –v  // 显示本地分支和服务器分支的映射关系
git branch -m master mymaster  // 分支重命名

git checkout branch_name   // 切换分支(和创建分支就差一个-b参数)
git checkout –b new_branch   //创建新分支,新分支的代码来自于当前分支
git checkout –b new_branch base_branch    // 基于base_branch创建新分支
git checkout -b new_branch origin/base_branch
git checkout – filename   // 撤销修改

git add ./*
git add file_name
git commit -m “”  // 添加注释
git commit -am “”  //提交并且加注释

git fetch  // 将远端所有分支的更新全部取回本地
git pull   // 取回远端当前分支的更新,再与本地当前分支合并,等同于先做git fetch,再做git merge
git pull origin next     // 取回origin主机的next分支,与当前分支合并
git pull origin next:master  // 取回origin主机的next分支,与本地的master分支合并

git push origin branch_name   // 将本地分支的更新,推送到远程主机
git push origin :branch_name   // 删除远程分支, :branch_name之间没有空格
git push origin --delete branch_name  // 删除远程分支
git branch -d local_branch_name    // 删除本地分支

git merge master  // 合并本地master分支到当前分支,比如当前处于dev分支,则把master上的代码merge到dev分支上
git merge origin/master  // 合并远程master分支到当前分支

git rm file_name  // 从git中删除指定文件


回退操作:
git reset --hard HEAD  // 复位,清空所有未提交的内容
git reset --hard HEAD^  // 回退到上一个版本
git reset --hard commit_id  // 回退到某个版本


暂存操作:
git stash 暂存当前修改
git stash apply 恢复最近的一次暂存
git stash pop 恢复暂存并删除暂存记录
git stash list 查看暂存列表
git stash drop 暂存名(例:stash@{0}) 移除某次暂存
git stash clear 清除暂存

修改最近一次的commit 信息

  • git commit --amend
  • git push -f   // 推送到服务端。

将提交添加到当前分支
git cherry-pick ${commit_id}

标签操作
git tag 标签名 添加标签(默认对当前版本)
git tag 标签名 commit_id 对某一提交记录打标签
git tag -a 标签名 -m ‘描述’ 创建新标签并增加备注
git tag 列出所有标签列表
git show 标签名 查看标签信息
git tag -d 标签名 删除本地标签
git push origin 标签名 推送标签到远程仓库
git push origin --tags 推送所有标签到远程仓库
git push origin :refs/tags/标签名 从远程仓库中删除标签


rebase

// 修改最近的 4 次提交记录
git rebase -i HEAD~4
// 显示的commit是按照提交顺序由远到近排序的
// 按照提示p、e、d、s修改即可,一般是将最后的设置为s

//撤销
git rebase --abort

// push时需要强制
git push -f


3.删除文件后需要 git add -A, 光 git add. 不行,区别如下:
git add 的几种参数区别

git add -A 保存所有的修改
git add . 保存新的添加和修改,但是不包括删除
git add -u 保存修改和删除,但是不包括新建文件。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值