Need help with a git command

Hi everyone,

I’m trying to push changes to repository but I’m getting the below message:

Your branch is ahead of 'origin/main' by 3 commits

I can’t push the changes because the size of one file is too large and every time I end up getting an error. How can I reverse these commits? I tried git pull --rebase and some other solutions from stackoverflow but nothing seems to work.

Thank you!

I’m no expert but…

First of all, if the file is too big too send, it should probably be in the .gitignore file.

Secondly, if you want to undo the more recent commit, but keep the file changes you made, you can do something like:

git reset HEAD~1

That will undo the most recent commit, but keep the changes you made as changes. In theory, you could do that three times to get back to before those three commits but keep the file changes. So, all the files will be the same, just that the changes that you made will not be tracked or committed.

If you don’t care about the file changes, you could do:

git reset --hard HEAD~1

but again, that will get rid of the changes that you made as part of the commit.

Again, I’m kind of clumsy with git, but that is my approach in cases like this.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.