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
45
votes
6 answers

How do I git add only lines matching a pattern?

I'm tracking with git some configuration files. I usually do an interactive git add -p but I'm looking at a way to automatically add all new/modified/deleted lines that match a pattern. Otherwise it's going to take me ages to do all the interactive…
Benoît
  • 3,355
  • 2
  • 29
  • 34
40
votes
2 answers

What's the difference between "git add -u" and "git add -A"?

Okay, so I was searching "How to Remove Manually Deleted files from Git" without actually doing git rm file.txt for each file when I came across "Removing multiple files from a Git repo that have already been deleted from disk". The two most…
Sheharyar
  • 73,588
  • 21
  • 168
  • 215
36
votes
2 answers

Any difference between git add . and git add --all?

Is there any difference between: git add . and git add --all ?
Pat
  • 1,198
  • 3
  • 12
  • 22
34
votes
2 answers

Why is split option missing in git add -p?

Trying to split a hunk into smaller ones by git add -p and split option, but entire file appears as one hunk and I can't split it. I can edit, but removing lines causes the patch to fail. git help add says I should have split, and I recall using…
32
votes
2 answers

What happens when you run `git add .git` in a Git repository?

While it seemed to do nothing, it gave no warning or error message. Any ideas?
Andres Riofrio
  • 9,851
  • 7
  • 40
  • 60
32
votes
7 answers

Why are changes in one branch visible in another branch?

I execute the following sequence of commands: git init rep cd rep/ echo '111' > 1.txt git add 1.txt git commit -m '1' git checkout -b dev echo '222' > 1.txt git checkout master more 1.txt As a result of these commands I see 222 And I do not…
Roman
  • 124,451
  • 167
  • 349
  • 456
30
votes
7 answers

Git add lines to index by grep/regex

I have a giant patch that I would like to break into multiple logical git commits. A large number of the changes are simply changing variable names or function calls, such that they could easily be located with a grep. If I could add to the index…
FazJaxton
  • 7,544
  • 6
  • 26
  • 32
29
votes
15 answers

Git won't add modified file

No idea why this is happening: git status On branch master Changes not staged for commit: (use "git add ..." to update what will be committed) (use "git checkout -- ..." to discard changes in working directory) (commit or discard…
Starkers
  • 10,273
  • 21
  • 95
  • 158
28
votes
3 answers

How to stage a rename without subsequent edits in git?

I have a file that I've renamed and then edited. I would like to tell Git to stage the rename, but not the content modifications. That is, I wish to stage the deletion of the old file name, and the addition of the old file contents with the new file…
Rhubbarb
  • 4,248
  • 6
  • 36
  • 40
28
votes
5 answers

How to edit Git "add patch" hunks/diffs/lines during selective staging?

I have a source file where 2 features have been added. In order to allow cherry-picking, I'd like to commit that in 2 phases: one for each feature. Until now, in similar situations, using git add -p served me well, to commit one feature while…
bart
  • 7,640
  • 3
  • 33
  • 40
25
votes
2 answers

Refresh staged files

In git, is there any (simple) way to modify the index so that only changes to files which are already in it are added? It sounds kind of complicated, but what I want to achieve is simple. Lets say my index looks like this (slightly stripped git…
axelarge
  • 947
  • 1
  • 9
  • 11
24
votes
2 answers

Can't use git add with --patch option

I recently updated Git to version 2.7.2.windows.1 (I am running Windows 7 64-bit). Since the update, I have been unable to run git add with the -p option on files within a certain directory (or its subdirectories) whose name is _ (an…
Carl Fink
  • 434
  • 3
  • 14
22
votes
1 answer

Untangle two lines with `git add -p`

I've got a file with the following changes: # Manual hunk edit mode -- see bottom for a quick guide @@ -280,6 +281,7 @@ if( foo ) { bla(); - test( true ); + removeThis(); + test( false ); } else How can I commit the change for…
vdboor
  • 21,914
  • 12
  • 83
  • 96
22
votes
3 answers

Use Git's patience diff algorithm for interactive add

I'd like to use Git's patience diff algorithm (the one you get if you invoke git diff with the --patience argument) with git add -p. How can I do this? Background: I'm working with some XML files, and git diff's normal algorithm produces pretty poor…
me_and
  • 15,158
  • 7
  • 59
  • 96
19
votes
1 answer

What are the options of `git add -p`?

Doing a git add -p I see a one diff and the list of choices : ~/workspace$ git add -p diff --git a/gulpfile.js b/gulpfile.js index cf91028..c3a0964 100644…
Hugolpz
  • 17,296
  • 26
  • 100
  • 187
1 2
3
21 22