简体   繁体   中英

Is it possible to recover from commiting the .metadata folder of an eclipse based IDE to git?

I'm using ST's IDE for STM32 microcontrollers, STM32Cube. It is based on eclipse, just with extra additions for working with microcontrollers. I have made the apparently fatal error of not adding the .metadata folder to the gitignore immediately upon creating the repository. This worked fine until I tried to revert to a previous commit, upon which I got a myriad of random merge conflicts on both text and binary files, mostly in the .metadata folder. I have tried to remove the .metadata folder from the repository, but git stubbornly refuses to ignore it despite using the methods describe in these answers:

https://stackoverflow.com/a/4308645/6181778
https://stackoverflow.com/a/30360954/6181778
https://stackoverflow.com/a/2163926/6181778 (for solving the alleged merge conflicts)

As far as the merge conflicts are concerned, they don't make any sense since I am the only contributor to the repository, so it is impossible for two different versions of a file to be committed. Git has now inserted a bunch of merge conflict stuff (most of which doesn't even have two sections, just a head and tail with no divider) into all my files, and STCube refuses to launch because of it. Is there any way to recover from this, or do I just need to try and salvage my code and start a new repository?

You mentioned that this happened after reverting to a previous commit. I suspect that you need to undo that revert first:

git reset --hard commit-before-revert

and then follow the instructions you linked to:

Step 1. Add the folder path to your repo's root .gitignore file.

path_to_your_folder/

Step 2. Remove the folder from your local git tracking, but keep it on your disk.

git rm -r --cached path_to_your_folder/

Step 3. Push your changes to your git repo.

At this point it should be safe to do the revert because git will ignore the .metadata folder now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM