I've pushed a bunch of files in my last commit, but I'd like to break that commit into two and move some files from the initial commit to the new commit.
Asked
Active
Viewed 2,173 times
-2
-
Possible duplicate of [Git: Remove committed file after push](https://stackoverflow.com/questions/18357511/git-remove-committed-file-after-push) – wjandrea Jul 02 '19 at 16:52
-
More possible duplicates: [How can I undo a `git commit` locally and on a remote after `git push`](https://stackoverflow.com/q/6459080/4518341), [How can I remove a commit on GitHub?](https://stackoverflow.com/q/448919/4518341) (not actually GitHub-specific) – wjandrea Jul 02 '19 at 16:55
-
Possible duplicate of [How to split last commit into two in Git](https://stackoverflow.com/questions/1440050/how-to-split-last-commit-into-two-in-git) – phd Jul 02 '19 at 17:50
-
https://stackoverflow.com/search?q=%5Bgit%5D+split+commit+in+two – phd Jul 02 '19 at 17:51
2 Answers
1
A bit dirty:
- First revert the commit by calling "git revert [commit number]"
- Then "git reset [commit number before your revert]".
- git add required files for first commit.
- git commit.
- git add files for second commit.
- git commit.
- git push origin ...
Hope this helps.

Tomer
- 1,594
- 14
- 15
1
Here are links to two stack overflow questions/threads, the first applying to already pushed code and the next applying to local, yet to be pushed code:
Based on your description, it seems to make the most sense to undo your last commit (the pattern git revert
followed by a git reset
should take care of the last commit), and then add the files by hand for the next commit (git add some/file
), and then commit those. After that, since you want to split it up into just two commits, you can use git add .
for the rest and then commit those changes.

John O'Rourke
- 31
- 4