2

I've working with git for pretty long time and still can figure out that. I add some files, I delete some files... When I want to commit, what do I do?

#1
git add .
git commit -m "123"

or

#2
git rm file1_I_removed
git rm file2_I_removed
git rm file3_I_removed
git rm file4_I_removed
git add .
git commit -m "123"

or

#3

git add -u
git commit -m "123"

Note that most probably I don't remember exactly what files I have deleted (even thought I can use git status and see them), and once I've deleted them, I want them to be deleted from repository as well without trying hard like

git rm file1_I_removed 
git rm file2_I_removed ... 
git rm fileN_I_removed 
Alan Coromano
  • 24,958
  • 53
  • 135
  • 205

1 Answers1

2

Try this:

git add -u

This command deletes all removed files, and updates what was modified.

If you have new files to add to the commit after that you can always git add . after.

aran
  • 10,978
  • 5
  • 39
  • 69
  • 1
    +1. Note: depending on what deletion you need to record in the index, you might want to consider `git add -u .` (git1.8.3+): see http://stackoverflow.com/a/2190440/6309 – VonC Jun 20 '13 at 16:41
  • 1
    But what about `git add -A .`? – Alan Coromano Jun 21 '13 at 03:07
  • `git add -A` . will do both `git add .` and git `add -u`, in that order. Maybe he doesn't want to add anything and just wants to delete removed files, that's why I proposed a `git add -u` and then, if desired, `git add .` Anyway, good note, |1 – aran Jun 21 '13 at 07:41