I know that "modified" in git refers to file's that are changed in any way, but is there a way to only commit "modified" files that I have added lines to? I don't want to commit files if lines were removed from.
Asked
Active
Viewed 97 times
0
-
Does this answer your question? [Simpler way to stage only modified files in Git (not deleted)](https://stackoverflow.com/questions/14368093/simpler-way-to-stage-only-modified-files-in-git-not-deleted) – Mohammad Dohadwala May 31 '21 at 12:51
-
@MohammadDohadwala Thanks for your reply, I'm afraid it's not what I need at it refers to deleted files and I need to "not commit" files that there was a content deleted in them (not the actual file) – JustABeaver May 31 '21 at 12:53
-
2What about `git add -p` to select what to commit ? – Ôrel May 31 '21 at 13:03
-
2@JustABeaver Modified lines will also appear as a deleted line + an added line. So you would **not** want to stage these, only pure additions, right? Seems suspiciously unusual and XY-problem-like. What's wrong with `add -p` as @Ôrel suggested ? – Romain Valeri May 31 '21 at 16:26
1 Answers
0
The simplest answer is to use the "git add" command to add the specific files you want committed. This is similar to the the suggestion above, which is "git add -p" which allows you to stage particular hunks for commit, interactively; but this is simpler.
git add filename-including-path
You can add them one at a time, or put multiple filenames on the command line.
To reiterate: If you don't want to commit all the changed files, then all you need to do is tell git which files you want committed. You know which ones you want. Git does not know what special treatment you want.

Randy Leberknight
- 1,363
- 9
- 17
-
Thanks! The problem is that it's an automatic system that does the actions and not human so it needs to know which files automatically...I don't think it's possible to be honest – JustABeaver Jun 02 '21 at 08:28