2

I want to delete older commit, because I had to separate it to 2 commits. So changes, that are at a5b4cd are same like changes in 2a0d40e + a8bb836.

2a0d40e Add sending
a8bb836 Add parsing
a5b4cbd Add sending and parsing     <--- I want to delete this
f6063ac First commit

I tried some git rebase -i and fixup here, but everytime, it will add changes from this "deleted" commit to another commit and that I dont want.

Mildas
  • 37
  • 5
  • Possible duplicate of [Remove local commit completely from tree](http://stackoverflow.com/questions/27984814/remove-local-commit-completely-from-tree) – George Hilliard Mar 08 '17 at 19:44

1 Answers1

2

Don't use fixup. Simply remove that line during your interactive rebase.

That will be enough for that commit to be dropped.

But then be prepared to have to force push (git push --force) which can be problematic on public branches.

Another option would be git revert (if you just want to cancel that commit rather than remove it from the history completely)

Before rebasing when I wanted to separate them I got Commit2 with File3 and File4. Then I wanted to separate it, so I have deleted File4, add Commit3 (just with File1 and File3), then added File4 and make Commit4.

Then the solution is different: While at Commit 4 (with all your files), do a

git reset --soft Commit1
git add File3
git commit -m "Add File3"
git add File4
git commit -m "Add File4"
VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
  • I tried removing line, but I get: 'The previous cherry-pick is now empty, possibly due to conflict resolution.' and 'Could not apply a8bb836... Add parsing'. – Mildas Mar 08 '17 at 19:48
  • @Mildas What git version are you using? (since this was discussed before: http://git.661346.n2.nabble.com/odd-behavior-with-git-rebase-td7399607.html) – VonC Mar 08 '17 at 19:53
  • @Mildas Considering http://stackoverflow.com/a/29638001/6309, you could try and drop as well a8bb836, and see if the final result is still what you want. – VonC Mar 08 '17 at 19:56
  • git version 2.7.4. And I tried as you said dropping a8bb836 too (both lines at one rebase) and then it successfully rebases, but then at log is only first and last commit. – Mildas Mar 08 '17 at 20:06
  • @Mildas Yes, that is the expected result. The question is: do you see al the files and content you want after such a rebase (dropping both commits)? – VonC Mar 08 '17 at 20:09
  • There are not changes from a8bb836. Only changes from that commit, that I didnt delete at rebase. – Mildas Mar 08 '17 at 20:18
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/137589/discussion-between-vonc-and-mildas). – VonC Mar 08 '17 at 20:21