Questions tagged [git-add]

git-add - Add file contents to the index

Before each commit in , you need to add file contents to the staging area.

The following will add all the files currently on the stage at the next commit:

$ git add .

This also adds the files recursively under the current working directory. Files previously tracked (i.e. they were in the last commit), still need to be added to the stage.

You can track new files specifically like so (where foo is the filename in this example):

$ git add foo

To add multiple files, separate them with a space like so (bacon and cheese being the other example files):

$ git add foo bacon cheese

References

330 questions
19
votes
2 answers

Undo multiple file and folder 'git add'

I executed git add . and now I want to revert that git add. How can I accomplish that?
hopper
  • 4,230
  • 8
  • 36
  • 49
18
votes
1 answer

`git add --patch` with `--word-diff`

git add --patch provides a great interface for reviewing unstaged changes and then staging only the ones that are wanted in the next commit. Great, except for one thing: there is no obvious way to choose which diff view to use. In particular, I…
user82216
18
votes
2 answers

Git add only all new files, not modified files

Is there a way to only add new files and not add modified files with git? That is, files that are listed as untracked with git status. Other than ofcourse adding each file separately. It's not absolutely necessary to do this in my case, the real…
Andreas Fliesberg
  • 339
  • 1
  • 3
  • 11
16
votes
2 answers

why it is not possible to git add .git/hooks/my-hook

I would like to have some hooks always present in a clone of a given repository. Is there a way to add a file in .git/hooks in the repository? Thanks
Mildred
  • 3,887
  • 4
  • 36
  • 44
16
votes
7 answers

Unable to Git-add with force

I get git-status at ~/bin: # Untracked files: # (use "git add ..." to include in what will be committed) # # screen/dev/ I run git add --force screen/dev/ I get the same git-status as before. I add each file in the folder…
Léo Léopold Hertz 준영
  • 134,464
  • 179
  • 445
  • 697
15
votes
2 answers

What is the meaning of the "bang" or "!" before the git command?

As you can see from this excerpt, there is a "!" before the git command. What's the point? [alias] commitx = !git add . && git commit - https://stackoverflow.com/a/8956546/1354543 I understand aliases and what the command itself is doing, but not…
Joe Collins
  • 458
  • 3
  • 12
14
votes
1 answer

git status: what is UU and why should add/rm fix it?

Here is the current state of this feature branch. Recent Steps: Remote development branch diverged Fetched remote development branch Stashed local feature branch's diverged changes that I want to keep Rebased feature branch from local development…
Dylan Valade
  • 5,565
  • 6
  • 42
  • 56
14
votes
3 answers

How do I use a pager for long git add --patch hunks?

When I interactively add diff hunks with git add --patch, I sometimes get hunks which are longer than the screen, but no ability to use less to page through the hunks. This is strange to me as I have already set: [core] pager = less -FRX…
Tom Hale
  • 40,825
  • 36
  • 187
  • 242
13
votes
3 answers

git stash and edited hunks

I totally love git add -p and git stash but I occasionally have the following problem, which is reproduced by the following sequence of commands: git add -p my_file: then I edit a hunk manually (using e) because the splitting that git suggests does…
Olivier Verdier
  • 46,998
  • 29
  • 98
  • 90
13
votes
1 answer

How to add specific files in git by their number in git status?

I often encounter the following scenario: modified: assembly/main.debug.s modified: ../src/cd/Config.java modified: ../src/cd/memoization/cfg/SubgraphFinder.java modified: ../src/cd/memoization/cfg/SubgraphMap.java modified: …
ben
  • 5,671
  • 4
  • 27
  • 55
13
votes
4 answers

Is it possible to skip the staging area and (also) commit untracked, new files to git?

Is it possible to skip the staging area and (also) commit untracked, new files to git in a single built-in, command-line command ? If not, what are the alternatives ?…
nutty about natty
  • 1,267
  • 2
  • 10
  • 17
13
votes
2 answers

What's the difference between git add * and git add ., if any?

git animals had this series of commands: git init git add * git commit -a -m ‘initial commit and release!’ What does git add * do compared to git add . (which I normally do) are they the same?
Kit Sunde
  • 35,972
  • 25
  • 125
  • 179
13
votes
2 answers

Recover files that were added to the index but then removed by a git reset

I added some files to the index but then by mistake I deleted them with git reset --hard. How do I recover them? Here's what happened: I added all files using git add . I then committed When I checked the status, there were still files that…
Jeff Eisley
  • 193
  • 1
  • 2
  • 10
12
votes
2 answers

Git: Undo local changes; git add . + git rm?

Need help figuring out a couple common workflows with Github. I come from a VS TFS background, so forgive me. Undoing Pending Changes Let's say I have cloned of a git repository to my local file system. At this point, the project's local files match…
user979672
  • 1,803
  • 3
  • 23
  • 32
12
votes
3 answers

Is there a way in git to split up changes in a single file into two commits?

So I a have a file: ... some code here.. ... some unrelate code here.. ... and I make the following changes to it: ... some code here that needs to be changed a bunch.. ... some unrelated code here.. ... Let's say I'm in the middle of some…
olleicua
  • 2,039
  • 2
  • 21
  • 33