Add new file to commit

4

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"?

    
asked by anonymous 06.03.2015 / 19:36

2 answers

5

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

    
06.03.2015 / 19:45
7

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 .

    
09.03.2015 / 10:15