Modifying a file after "git add"

As mentioned in other answers and by yourself, git add should work. However, I think you already have a valid commit (which was not passing some test) and with another git add and git commit, you are just adding a new commit to your branch. The falty one still exsits and fail. There are a bunch of solution you can do here. Just two examples coming into my head at the moment:

git rebase --interactive HEAD~2 

This gives you a editor window where you can squash your two commits into one. Just change the pick in front of your second commit to f or s and save the file.

Another way could be to use git commit --amend

This will allow you to modify last commit. However, I recommend to read documentation for both.


Is there a way to update the files that are staged for a commit, without having to un-add and re-ad them?

No need to Un-add and re-add them

Just again add that file

git add file

After modifying any added file when you see git status -s

MM filename

so when you again add it then it will become

git add filename
git status -s
M  filename

In git, files (per se) aren't staged, changes are. So when you do git add <filename>, it is the current state of that file that is staged. If you change the file and want to add those changes as well, you just do another git add.


You just git add the file again and commit.

Tags:

Git