Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (29.3k points)

Sometimes after I did a commit, I found out that I left out a file which should also be included in the commit but actually not. What I often did was commit again.

git add the_left_out_file

git commit "include the file which should be added in the last commit"

I think it might not be a good idea to do so, what I want to do is just include the file without adding a commit. Something like this,

git add the_left_out_file

git add_staged_files_to_previous_commit

Is it possible?

1 Answer

0 votes
by (50.2k points)

For modification of existing, unpushed commit messages we use following commands.

$git commit --amend 

       Or

$git commit --amend -m “new message”

  Where 

$git commit --amend 

will open an editor where you can edit the message, and you can directly give the modified message to existing and unpushed commit messages.  

Then for this question, you could use:

git add the_left_out_file

git commit --amend --no-edit

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Jul 22, 2019 in DevOps and Agile by humble gumble (19.4k points)

Browse Categories

...