Git-Github从提交中恢复更改



我已经提交了一些从功能分支到远程主分支的更改,并打开了pull请求。但我忘了修复phpcs违规(运行代码嗅探器(,我需要在文件/提交中没有更改时和我所做的更改之间的区别-我需要回到提交前的状态-让所有行都更改为";修改的";我需要为该特性分支的3次提交做这件事。请有人帮助我如何实现这一点,或者它是如何命名的?

使用交互式rebase来编辑/重做所有提交。您需要按照git rebase文档中拆分提交部分提到的过程进行操作,而不需要实际拆分提交。

在运行此操作之前,请确保拥有分支的备份和干净的工作副本(git stash push -u(。

git rebase -i $basecommit
# change "pick" to "edit" for the commits you want to redo
# rebase will stop at first "edit" commit
git reset --soft HEAD^
# run your tool, make necessary changes
# add changes
git commit -C HEAD@{1} # make a new commit reusing message and author from the commit before reset
# resolve potential conflicts
# rinse and repeat

另一种选择是使用git cherry-pick:

git checkout $basecommit^{commit} # go to detached HEAD state
git cherry-pick --no-commit $firstcommit
# run your tool, make necessary changes
# add changes
git commit -C $firstcommit # make new commit reusing message and author from first commit
# repeat for $secondcommit, $thirdcommit, etc.
git checkout -B $yourbranch # label the newly created history with your branch name

最新更新