简体   繁体   中英

“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....

Most IDE reflects the staging area to real Git operations. (I'm using VS Code, and it does.) So, first unstage all files with:

git reset .

Then, set your files to be staged via git add or the IDE buttons. There should be a plus button for a file, depending on the IDE interface.

Finally, execute git commit --amend --no-message . The semantics should be same as normal commit.


If you can't figure out how to do the things above, doing an interactive rebase to squash the commits also helps. See How to modify existing, unpushed commits?

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 fill index. At (2) I commit necessary files leaving all other ( file2 and fileZZZ ) in index, at (3) I add missing file2 fix leaving fileZZZ in index.

It is possible to work with Git as if there is no staging area.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM