(Replace commit_count with number of commits that you want to edit.) This command launches your editor. Mark the first commit (the one that you want to change) as “edit” instead of “pick”, then save and exit your editor. Make the change you want to commit and then run
# You can reset your head to n number of commit# NOT a good idea for changing last commit message,# but you can get an idea to split commit into multiple commitsgit reset --soft HEAD^
# It will reset you last commit. Now, you# can re-commit it with new commit message.
使用重置将提交拆分为更小的提交
git reset也可以帮助您将一个提交分解为多个提交:
# Reset your head. I am resetting to last commits:git reset --soft HEAD^# (You can reset multiple commit by doing HEAD~2(no. of commits)
# Now, reset your head for splitting it to multiple commitsgit reset HEAD
# Add and commit your files separately to make multiple commits: e.ggit add app/git commit -m "add all files in app directory"
git add config/git commit -m "add all files in config directory"
$ git reset @~3 # Go back three commits$ git reflogc4f708b HEAD@{0}: reset: moving to @~32c52489 HEAD@{1}: commit: more changes4a5246d HEAD@{2}: commit: make important changese8571e4 HEAD@{3}: commit: make some changes... earlier commits ...$ git reset 2c52489... and you're back where you started