Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【20170307】【GIT】移除某个Commit(非第一个) #81

Closed
zhongxia245 opened this issue Mar 7, 2017 · 0 comments
Closed

【20170307】【GIT】移除某个Commit(非第一个) #81

zhongxia245 opened this issue Mar 7, 2017 · 0 comments

Comments

@zhongxia245
Copy link
Owner

时间:2017-03-07 17:27:04
作者:zhongxia

一、背景

  1. 由于开发任务A的时候,提交了一些东西到master上,任务还没有结束,并且又提交了一部分代码到个人仓库的master上,
  2. 现在开发任务B,从 个人 master 创建分支,然后开发完成后, 提交代码,
  3. 提交后,创建一个Merge Request, 发现包含 任务A的一部分代码
  4. 如何在任务B分支,去掉任务A的部分代码,

想要的效果

创建的Merge Request ,只包含任务B的代码

二、git 回退知识点

# 只是删除了commitId之后的commit记录,但是代码改动仍然存在
git reset --soft commitID 

# 彻底的回到CommitID13:39时候的版本,之后的改动不存在了
git reset --hard commitID 

三、具体操作案例

# 1. 查看任务A相关代码commit的id
git log 

# 2. 回退到不包含任务A部分代码的commit 位置
git reset --soft commitid

# 3. commit之后的代码,还存在 modified 区域
git rm 任务A的文件

# 4. 提交代码
git commit -am '提交任务B代码,任务B描述'

# 5. push 到个人远程仓库分支
git push -f 

# 6. 搞定
@zhongxia245 zhongxia245 changed the title 【20170307】【GIT】移除指定版本的Commit,并保留其他之后的其他Commit 【20170307】【GIT】移除指定版本的Commit Mar 7, 2017
@zhongxia245 zhongxia245 changed the title 【20170307】【GIT】移除指定版本的Commit 【20170307】【GIT】移除某个Commit(非第一个) Mar 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant