Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modifying a file after "git add"

Tags:

git

Scenario

Due to PHPMD and PHPCS checks that run during a commit, I often need to modify files that have already been affected by "git add".

If I modify a file that is added, and retry the commit, the changes aren't recognized, so the commit will fail again.

I then need to "git reset" the files to un-add them, then re-"git add" them and run the commit again.

Question

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

I apologize if this is a duplicate. All my searches seem to only show results for different problems with similar words.

like image 220
Alec Avatar asked Jan 05 '15 09:01

Alec


People also ask

How to add all modified files in Git add?

When you are dealing with Git add, you have multiple options to add all modified files. Let’s look at a few scenarios to understand the possibilities. Let’s initialize a new project. In this project, we have added a ReadMe.txt file. We used the “git add” command to add the ReadMe.txt. The add command is not only for adding files.

What does Git add [ filename] do?

git add [filename] selects that file, and moves it to the staging area, marking it for inclusion in the next commit. You can select all files, a directory, specific files, or even specific parts of a file for staging and commit. This means if you git add a deleted file the deletion is staged for commit.

What is the Git add command?

The git add is a command, which adds changes in the working directory to the staging area. With the help of this command, you tell Git that you want to add updates to a certain file in the next commit.

How do I add changes to a git repository?

Then, you have to use the commit command to make the changes official. When you are dealing with a lot of files and folders, it’s difficult to individually add each change. So you can use the following commands: $ git add .


2 Answers

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.

like image 68
drRobertz Avatar answered Sep 22 '22 00:09

drRobertz


You just git add the file again and commit.

like image 41
grasshopper Avatar answered Sep 24 '22 00:09

grasshopper