Today I survived a shocking experience. I’m working on an open source framework. Some of the features I’ve been doing at home on a cloned git respository. I have commited about 6 times for a feature. Another change of the feature I was doing on another machine at my workplace. These changes were another two commits. I then patched the two commits I did on my work computer and applied them at home upon the other six commits with gitextensions (version 2.24).
When I applied the patches gitextensions was hanging indefinitely in the patch apply mode. After waiting for about 5 minutes I aborted the patching process. This left my whole repository in the middle of rebase state. Worst of all was that all my commits from the last week where gone! My blood pressure raised immediately. I tried several approaches: Abort the merge process several times, skip the patches etc. but none of these approaches were successful. Git always complaint that the folder .git/rebase-apply could not be removed. How can this state be resolved? I’ll show you how!
You need to do the following steps:
- Close gitextensions
- Open your repository in your file browser and delete the folder .git/rebase-apply
- Open the folder .git/logs/refs/heads/ and open the file master with your favorite editor
- Look for the commit you need
fd16b3de73...df221c0 cb288d1f89a5565a...df1a93a44e User 1318178002 +0200 commit: Text cb288d1f89...a93a44e 15b008d9e5713868...gdf7345414 User 1318451633 +0200 commit: Text
- You need to copy the second SHA1 hash of the desired commit.
- Open git bash and type
git checkout -b featurename 15b008d9e5713868...gdf7345414 // this will create a branch with name "featurename"
- Re-apply the patches one by one with apply patch and choose a single file in the order of the patch prefix!
- You are saved!
Hope that will help some people until the bug is resolved!
Caution: I will not take any responsibility when you mess up your repository even more. Deleting folders in .git is dangerous and can lead to serious damage of your repository! Be cautious!