I'm trying to write a .gitignore file. I'd like to get a preview of everything that would be added if I were to run "git add -u". Is that possible? Or, if I ran "git add -u", and some stuff got added that I don't want, can I undo the entire thing? Then I'll tweak my .gitignore some more and repeat.
Thanks
" git add -u " only adds currently tracked files (which have been modified) to the staging area and also checks if they have been deleted (if yes, they are removed from staging area). This means that it does not stage new files.
git add. The git add command adds a change in the working directory to the staging area. It tells Git that you want to include updates to a particular file in the next commit. However, git add doesn't really affect the repository in any significant way—changes are not actually recorded until you run git commit .
The git add command adds new or changed files in your working directory to the Git staging area. git add is an important command - without it, no git commit would ever do anything. Sometimes, git add can have a reputation for being an unnecessary step in development.
I think you're looking for:
git add -n
.. which is the --dry-run
short switch :)
Edit: from the root of the repository, try:
git add -n .
If you were to mistakenly add files that were supposed to be ignored, and you didn't catch it in the dry run, you'd just use:
git reset HEAD --
.. which would essentially unstage the files.
Note that the same preview won't work with an interractive add.
Git 2.32 (Q2 2021) is now clearer: "git add -i --dry-run
"(man) does not dry-run
, which was surprising.
The combination of options has taught to error out.
See commit a1989cf (05 May 2021) by Øystein Walle (Osse
).
(Merged by Junio C Hamano -- gitster
-- in commit 47fa106, 14 May 2021)
add
: die if both--dry-run
and--interactive
are givenSigned-off-by: Øystein Walle
The interactive machinery does not obey
--dry-run
.
Die appropriately if both flags are passed.
And: With Git 2.34 (Q4 2021), stop "git add --dry-run
"(man) from creating new blob and tree objects.
See commit e578d03 (12 Oct 2021) by René Scharfe (rscharfe
).
(Merged by Junio C Hamano -- gitster
-- in commit 6ffb5fc, 25 Oct 2021)
add
: don't write objects with --dry-runReported-by: [email protected]
Signed-off-by: René Scharfe
When the option
--dry-run/-n
is given, "git add
"(man) doesn't change the index, but still writes out new object files.
Only hash the latter without writing instead to make the run as dry as possible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With