回滚两个提交。重新应用第二次提交。分支并应用第一次提交
Rollback two commits. Reapply second commit. Branch and apply first commit
在我的项目中,我最近做了两次提交。提交在不同的文件集上。我还远程推送了这些提交。像下面这样的东西-
git commit file-a file-b -m "first commit of new features"
git commit file-c file-d -m "second commit of new features"
git push -u origin master
我想做以下事情-
- 将 master 回滚到第一次提交之前,然后应用
仅 第二次提交。
- 此时创建一个功能分支
并应用第二次提交(它也应该有第一次提交)。
这是否可以通过简单的方式实现?我考虑过创建和使用具有 git diff 的补丁文件,但我想我会先检查是否有更好的方法。
Create a feature branch at this point and apply the second commit (it should have the first commit too).
只需在您的 master
当前所在的位置创建一个功能分支:
git branch feature_branch
Rollback the master to before the first commit and then apply only the second commit.
git reset --hard @~2
重新排序功能分支上的提交
git checkout feature_branch
git rebase -i master
# switch second and first commit order
然后将 master 重置为 feature_branch~1(这是第二次提交)
git checkout master
git reset --hard feature_branch~1
最后,全部推送
git push --force origin master
git push -u origin feature_branch
在我的项目中,我最近做了两次提交。提交在不同的文件集上。我还远程推送了这些提交。像下面这样的东西-
git commit file-a file-b -m "first commit of new features"
git commit file-c file-d -m "second commit of new features"
git push -u origin master
我想做以下事情-
- 将 master 回滚到第一次提交之前,然后应用 仅 第二次提交。
- 此时创建一个功能分支 并应用第二次提交(它也应该有第一次提交)。
这是否可以通过简单的方式实现?我考虑过创建和使用具有 git diff 的补丁文件,但我想我会先检查是否有更好的方法。
Create a feature branch at this point and apply the second commit (it should have the first commit too).
只需在您的 master
当前所在的位置创建一个功能分支:
git branch feature_branch
Rollback the master to before the first commit and then apply only the second commit.
git reset --hard @~2
重新排序功能分支上的提交
git checkout feature_branch
git rebase -i master
# switch second and first commit order
然后将 master 重置为 feature_branch~1(这是第二次提交)
git checkout master
git reset --hard feature_branch~1
最后,全部推送
git push --force origin master
git push -u origin feature_branch