Reputation: 9690
Some of my lastly commited files are unfortunately too big for github, so I would like to remove these from the latest commit, making it possible to push the other files. I have tried using git reset --HEAD for this, but it seems to only work if you haven't commited the files yet. Any other ideas?
Upvotes: 2
Views: 75
Reputation: 32731
This should work for you:
git rm
the offending filesgit status
should show the files as deletedgit commit --amend
to amend the last commit, the files should no longer be includedgit push
See this transcript:
[root@/tmp/test master]touch b c
[root@/tmp/test master]git add b c
[root@/tmp/test master]git commit -m "Add b and c"
[master 1cd809f] Add b and c
0 files changed
create mode 100644 b
create mode 100644 c
[root@/tmp/test master]git rm c
rm 'c'
[root@/tmp/test master]git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# deleted: c
#
[root@/tmp/test master]git commit --amend -m "Add only b"
[master 9c5809e] Add only b
0 files changed
create mode 100644 b
[root@/tmp/test master]git diff HEAD^..HEAD
diff --git a/b b/b
new file mode 100644
index 0000000..e69de29
Note: This only works if the offending files were added in the last commit. In other cases refer to Remove sensitive data in the GitHub help, it explains to delete a file from the complete history.
In case this it not wanted either you can try an interactive rebase (git rebase -i <commitish>
) and my method above.
Upvotes: 3