Search code examples
androidgitkotlingit-lfs

Git lfs removed code from every single file - Kotlin


I was using git lfs for some large files as I had committed prior to use it, so I had to use git lfs migrate import as provided here which re-wrote the commits and then I was able to push it on the server. But, in turn, it has changed whole project's every .kt, .xml file to these 3 lines:

version https://git-lfs.github.com/spec/v1
oid sha256:e1bc1da7265eea2b374ddf30546ddabfa
size 21093

Opening any file over Github is not working as well but downloading a file and opening it works which means I still have a backup plus the ZIP backup I always create. How to clear/rollback this mess because I've a huge project?.

Terminal Log:

C:\Users\X\Documents\Projects\X>git lfs migrate import
migrate: override changes in your working copy? [Y/n] y
migrate: changes in your working copy will be overridden ...
migrate: Fetching remote refs: ..., done.
migrate: Sorting commits: ..., done.
migrate: Rewriting commits: 100% (2/2), done.
  master        f42b3a9d9874f2da0922 -> 7a1881a54a114be8474
migrate: Updating refs: ..., done.
migrate: checkout: ..., done.

C:\Users\X\Documents\Projects\X>git lfs migrate info
migrate: Fetching remote refs: ..., done.
migrate: Sorting commits: ..., done.
migrate: Examining commits: 100% (2/2), done.
*.xml   109 KB  845/845 files(s)        100%
*.kt    80 KB   621/621 files(s)        100%
*.png   22 KB   173/173 files(s)        100%
*.ttf   1.6 KB    12/12 files(s)        100%
*.apk   1.2 KB      9/9 files(s)        100%

C:\Users\X\Documents\Projects\X>git push -u origin master
Uploading LFS objects: 100% (1695/1695), 1.4 GB | 3.7 MB/s, done.
Enumerating objects: 3332, done.
Counting objects: 100% (3332/3332), done.
Delta compression using up to 16 threads
Compressing objects: 100% (1823/1823), done.
Writing objects: 100% (1852/1852), 256.98 KiB | 735.00 KiB/s, done.
Total 1852 (delta 7), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (7/7), completed with 3 local objects.
To https://github.com/X/X.git
   6ee589d..7a1881a  master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.

Also, now I can't see Git in Android Studio, no options even in the above VCS menu. I checked the whole project, it has removed code from every single file, even from gradle files, .idea configurations files, text files etc.


Solution

  • I've solved the issue which was new for me. It might help others.

    So, What I wanted to do was to support large files, I used git lfs but as I had already committed the code, I had to use git lfs migrate import which edits already committed changes and add the "supposedly" big files to its repository capable to store large files.

    But, this command added all the files and provided a pointer as mentioned in the comments by Torek.

    I read their help docs and to resolve the issue, first I ran a command git lfs checkout which brings back the original content of the files from the repo to local files and then I removed all type of files added to .gitattributes except few for which I used git lfs on the first place. git lfs works with .gitattributes.

    Then, I just did a new commit and push and everything works fine now. Hell of a journey at midnight, blew my sleep.