2
crisz
4y

I had mistakenly added a large file to a commit, and I'm now spending 3 hours of my life just to remove it and being able to push.

I've deleted the file from tracking, but it remained in history so when I try to push, github rejects to continue.

And, still worse, trying various solutions on StackOverflow I've done a mess on the history which now looks unrelated to the remote one, and I think it's a never-end catastrophe.

It's absurd how badly designed is git, and how hard it is to use besides the 3 commands that you learnt by heart

Comments
  • 2
    Been there, done that. First months at my first job, I somehow decided it's a good idea to commit a 1 GB .PSD.

    Can't remember how and whether I fixed it at all (I must've), but what I'd try now is resetting the local branch to the commit just before adding the file, then force pushing. I'm not a git expert, but that sounds about right to me. I might be wrong of course.
  • 0
    @kamen that's a good idea, but I should go 7 commits back, and I don't even know if it's now possible
  • 0
    now I deleted the files through "git filter-branch", I'm trying "git push --force", and it's pushing 3000 objects. What the hell is it pushing?
  • 3
    * backup file
    * delete file
    * comit "deleted"
    * restore file
    * add to gitignore
    comit

    optional : SquashCommits so noone can see that ;p
  • 5
    Git isn't badly designed, you just haven't learned how to use it properly yet.

    Have you tried an interactive rebase?

    git log

    Find the hash of the commit you want to remove

    git rebase -i commit_hash~

    (The ~ is important)

    Vim/nano will open up

    Change "pick" to "drop" on the commit you wish to remove

    Save and close editor

    Fix conflicts if any

    git push --force origin branch_name

    Done

    https://stackoverflow.com/questions...

    It just tried it in a repository of mine, it seems pretty straight forward.
  • 3
    The point of version control is to show the history. It shouldn't be easy to rewrite history.

    @NoToJavaScript it's still in the repo after that, and everyone has to download it if cloning the full history of that branch
  • 0
    @electrineer True. But how often full history is downloaded ?
  • 1
    Git is an abomination, and one day we're going to look back on it as an industry and wonder what we were all smoking to ever have thought it was a good idea.
  • 2
    @fzammetti having worked with three different version controls before git I can say git is the best so far.

    Sure there might come something better but git has survived and replaced most of the older ones.

    You just have to really follow the rules OR learn how it really does work to be able to fix problems.

    But many of the older ones was worse in that once you had done something stupid you could not easily back track.

    You might have to manually setup versions to preserve and any changes in between would be lost :/
  • 1
    Git, compared to svn, is good. If you're having so many problems, use a gui. Gitkraken is pretty good. It even let's you undo changes to the repo.
  • 2
    @NoToJavaScript Git always downloads the full history, there's no difference between client and server. For text repos that's fine. I've seen several gb build tools in a repo, made it a bit slower but from a local server, no biggie
  • 1
    @NoToJavaScript There's the "--depth" flag that can be added (with a numeric argument denoting the number of commits including the last one) when cloning, but unless you provide that flag, full history of the repo is cloned.

    https://stackoverflow.com/questions...
  • 0
    @NoToJavaScript I didn't mean to delete the file, just wanted to untrack it
  • 1
    @neeno yes but I wanted to remove a file from a commit, not a commit. I've solved now, I'll try it the next time just in case, thank you.

    By the way, also the worst designed software can be used if you learn how to use it. That's what make it bad designed, you've to learn it by heart.

    For example, what's the purpose of ~ in your solution? I should do some research for that, and it could have been avoided
  • 2
    @crisz you're confusing ease of use with good design. IMHO git is very well designed, but not noob friendly at all, you just have to learn how to use it as with any other tool.

    I don't know git by heart, I just understand the main concepts and that allows me to search for the answers to my questions on Google.

    You can easily find out what ~ means by searching it on google, it basically allows you to select the parent of the commit you specified.

    I don't want to sound rude, but stop saying stuff is badly designed before you've learned how to use it.
  • 2
    @neeno very true.

    Also, git was designed specifically for managing the linux kernel and follows the same philosophy as most linux tools.

    Its a command line tool that does one task, version control, and it is powerful.

    It was never designed with friendly for beginners in mind but for managing the most complex software projects that exists.

    I mean, Microsoft have replaced their own tool with git for windows, that is a good sign its a good tool.

    And to be honest, once you need some of the more complex features, git IS easy to use compared to all previous tools. And i switched from using a gui version just because I found that it hid to much of the features.
Add Comment