Ask Your Question

How can I commit only files that were modified in Git, not files that were deleted?

asked 2023-04-04 11:06:49 +0000

qstack gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2023-04-04 11:08:05 +0000

qstack gravatar image

To commit only files that were modified in Git, and not include files that were deleted, you can use the following command:

git commit -m "commit message" $(git ls-files -m)

The git ls-files -m command lists all files that have been modified. The $(git ls-files -m) expression substitutes the output of the git ls-files -m command as arguments to the git commit command. This means that only the modified files will be included in the commit.

Note that this command will only commit modified files that are already tracked by Git. If you have new files that you want to include in the commit, you will need to use git add to stage them first. Also, if you have deleted files that you want to exclude from the commit, you will need to use git reset or git checkout to unstage or discard the changes to those files.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer

Question Tools

1 follower


Asked: 2023-04-04 11:06:49 +0000

Seen: 22 times

Last updated: Apr 04 '23