前端干货-常用的git命令

72 阅读1分钟

Git创建本地分支并推送到远程:

  • 查看所有分支 git branch -a
  • 撤销本地提交 git reset head~ 
  • 本地创建新的分支 git branch branchname
  • 切换到新分支 git checkout gh-dev
  • 创建加切换 git checkout -b branch-name
  • 将新分支推送到远程 git push origin [branch name]
  • 克隆指定分支 git clone -b <指定分支名> <远程仓库地址>
  • 删除不存在的分支  git remote update origin -p
  • 删除本地分支 git branch -d name
  • 查看当前git配置   cat .git/config
  • 根据已有tag创建分支 git checkout -b 新分支 tag名
  • 查看当前使用的源   git remote -v
  • 删除过期的源 git remote rm origin 
  • 更新 access_token git remote set-url origin http://uername:access-token@xxx.git
  • 添加新的源 git remote add origin-name http://uername:access-token@xxx.git

在某个分支  修改内容并提交

1) 根据tag创建分支

git branch branchname tagname

git checkout branchname

2) 提交更改的code 

git add .

git commit -m "Fix included"

    或者使用 cherry-pick 合并一个commit

git cherry-pick  {commitid}

3) 删除本地tag,并重新创建该tag

git tag -d {tagname}

git tag {tagname}

4) 删除远程tag,并push code重新生成远程tag

git push origin --delete {tagname} // deletes original remote tag

git push origin {tagname} // creates new remote tag

5)  Update local repository with the updated tag

git fetch --tags