Alex
Alex

Reputation: 1537

Stuck in a git commit

I have added several files by mistake with

git add <file name>

Then I have run

git commit -m '..'

However, some files where too big and it failed when I run git push - now I'm stuck and I can't unstage those big files.

I've tried with 'git reset', 'git rm' but every time I try to push these big files reappear! How do I reset everything?

Upvotes: 0

Views: 2420

Answers (1)

eftshift0
eftshift0

Reputation: 30317

Normally what you do in this cases is amend the revision you created to remove the files..... so if you have created revisions after that revision where you added thenm, it won't work because those files are already part of the history of the project.... so, go back to the revision where you added them by mistake (use the ID), rm --cache those files and amend. Then you could push into the remote.

git checkout id-of-the-revision-where-I-added-the-files
git rm --cache file1 file2 file3 etc
git commit --amend --no-edit
# if everything is fine, move the branch pointer and push
git branch -f my-branch
git checkout my-branch
git push some-remote my-branch

That should be good enough

Upvotes: 1

Related Questions