How do I add new files to a commit already done in Git, without creating a new commit?
If you've already pushed the remote server, such as "re-committing"?
How do I add new files to a commit already done in Git, without creating a new commit?
If you've already pushed the remote server, such as "re-committing"?
You should use the parameter --amend
, if the last commit
git commit --amend
git add file2.txt
And when using push:
git push --force <repository> <branch>
Reference: link
If you make --force
, and other authors have created new commits however, those commits will be permanently deleted . --force
is recipe for disaster and should be avoided at all costs.
--amend
is recommended only if the commit has not yet been published.
As in this case the commit has already been published, it is best to create a new commit with the new files. amend
is rewriting history, it's lying to git .