git分支的创建与合并操作

git分支操作

Git分支操作(<name> ---> 分支名)

查看分支:git branch

创建分支:git branch <name>

切换分支:git checkout <name>或者git switch <name>

创建+切换分支:git checkout -b <name>或者git switch -c <name>

合并某分支到当前分支:git merge <name>

删除分支:git branch -d <name>

克隆指定分支: git clone -b <name> origin

(pull/拉取)指定分支: git pull origin <name>

修改本地分支名: git branch -m <旧分支名> <新分支名>

删除远程分支: git push --delete origin <旧分支名>

将新分支名推送到远程仓库: git push origin <name>

Git撤销上次commit提交

Git撤销上次commit提交(还在本地)

1.git reset --soft head~1 (撤销上一次commit, 不会撤销git add)

2.git reset head~ (撤销上一次commit, 同时撤销git add)

Git版本回退 (git log 可以查看 commit_id)

Git版本回退()

1.git reset --hard head^ (回退到上个版本)

2.git reset --hard head~2 (回退到第2个版本)

3.git reset --hard commit_id (回退到指定版本)

谨慎操作 回退之后就看不到回退版本之前的 commit_id 了

Git remote(修改远程仓库)

1.查看远程仓库: git remote -v

2.删除远程仓库: git remote rm origin/仓库名

3.添加远程仓库: git remote add origin/仓库名 URL

Git合并历史 – (refusing to merge unrelated histories)

git pull origin master --allow-unrelated-histories

Git tags

1. git tag -a v版本号 -m "说明"
2. git push origin v版本号

猜你喜欢

转载自blog.csdn.net/weixin_44953227/article/details/106989465