Search code examples
gitgit-amend

"git commit --amend" without "git add" / changing staging area


After further development I need to add additional changes to previous commit.

I've made a lot of changes including from IDE, that handle file renames, creating new files, etc.

So git status shows a lot of files in staging area.

I do not want to add this files with git commit --amend --no-message.

Can I list these files as arguments to git commit --amend --no-message? Any other possibilities without disturbing index?

I think about stashing index - but it is complicated thing to list 40 files to ignore instead 2 files for amend....


Solution

  • After experimenting I found an easy (and obvious) solution:

    $ echo x >> file1
    $ echo x >> file2
    $ echo y >> fileZZZ
    
    (1)$ git add .
    
    (2)$ git ci -m fix -- file1
    
    (3)$ git commit --no-edit --amend -- file2
    

    At (1) I add everything to the index. At (2) I commit only selected files leaving others (file2 and fileZZZ) in the index, at (3) I add missing file2 fix leaving fileZZZ in the index.

    It is possible to work with Git almost ignoring the staging area.