-2

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.

doctopus
  • 5,349
  • 8
  • 53
  • 105
  • 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 Answers2

1

A bit dirty:

  1. First revert the commit by calling "git revert [commit number]"
  2. Then "git reset [commit number before your revert]".
  3. git add required files for first commit.
  4. git commit.
  5. git add files for second commit.
  6. git commit.
  7. 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.