1

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

gavenkoa
  • 45,285
  • 19
  • 251
  • 303
  • Use `git reset` to unstage files. – Tatsuyuki Ishi Apr 26 '17 at 08:50
  • IDE helps me to add new files rename old ones and I don;t like to lose that work. – gavenkoa Apr 26 '17 at 08:53
  • Being 16k+ and relying everything on IDE? Anyway, `git reset` doesn't alter your work, but just changes the state from "staged" to "unstaged". – Tatsuyuki Ishi Apr 26 '17 at 08:54
  • Sorry, it's Java world. I have 100 files to commit and 10 files to ignore and it is nightmare to check what to keep and what to commit. Emacs able to commit without disturbing index but I don't know how to amend without disturbing index. I think about putting necessary file to **commit and squashing two of them** instead of amending... – gavenkoa Apr 26 '17 at 09:01
  • 1
    Create a new branch and commit on it what you already have in the index. Checkout the previous branch again, amend the last commit. Rebase the new branch on top of the current branch then merge them (fast-forward); or just cherry-pick the commit from the new branch in the current branch. Remove the new branch when you don't need it. – axiac Apr 26 '17 at 09:06

2 Answers2

3

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.

gavenkoa
  • 45,285
  • 19
  • 251
  • 303
1

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?

Tatsuyuki Ishi
  • 3,883
  • 3
  • 29
  • 41