您的位置:首页 > 运维架构

git operation

2016-03-18 15:44 330 查看
1.git  删除远程仓库的某次错误提交
假设你有3个commit如下:
commit 3 commit 2 commit 1 
其中最后一次提交commit 3是错误的,那么可以执行:
git reset --hard HEAD~1 
你会发现,HEAD is now at commit 2。
然后再使用git push --force将本次变更强行推送至服务器。这样在服务器上的最后一次错误提交也彻底消失了。值得注意的是,这类操作比较比较危险,例如:在你的commit 3之后别人又提交了新的commit 4,那在你强制推送之后,那位仁兄的commit 4也跟着一起消失了。

2. git merge
--no-ff 
Create a merge commit even when the merge resolves as a fast-forward. This is the default behaviour when merging an annotated (and possibly signed) tag. 
我们在将Develop分支发布到Master分支时,可能采用如下的命令:
# 切换到Master分支
git checkout master
# 对Develop分支进行合并
git merge --no-ff develop

3.git cancel local commit
refer: http://blog.jobbole.com/87700/
git reset <last good SHA>  :keep modification
git reset --hard <last good SHA> : delete modification
git reset 会把你的代码库历史返回到指定的 SHA 状态。 这样就像是这些提交从来没有发生过。缺省情况下, git reset 会保留工作目录。这样,提交是没有了,但是修改内容还在磁盘上。这是一种安全的选择,但通常我们会希望一步就“撤销”提交以及修改内容 — 这就是 --hard 选项的功能。

4. git create new repo from url
copy repo1 to repo
1.create new repo(git clone https://*.git)
2.cd the repo1 and 
$git remote add origin2 https://*.git
$git push -u origin2 --all
//git push -u origin2 —tags
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: