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
5
votes
3 answers

Git one-liner for applying a patch interactively

I have this patch file, it contains a bunch of modifications that I'd like to apply to a git branch. But I don't want to make one unique commit with all those modifications, instead I'd like to split it into 2 or 3 commits. I know I can achieve this…
arainone
  • 1,928
  • 17
  • 28
5
votes
2 answers

How do I move an unstaged file to untracked?

Say this is what I'm looking at in git status: Changes not staged for commit: modified: Makefile.in Untracked files: ../node_modules/somepath/inverter_packet.js What I want to do is something like move Makefile.in from 'Changes not staged…
J.M. Janzen
  • 671
  • 1
  • 8
  • 19
5
votes
2 answers

Git patch - patch does not apply

I'm trying to split changes into several commits, but I'm facing an issue when manually editing a hunk. Original hunk: @@ -116,8 +116,8 @@ context context - remove 1 - remove 2 - remove 3 + add…
Alex Ferg
  • 801
  • 1
  • 9
  • 17
5
votes
4 answers

Disable git add . command

Many times I mistakenly add unwanted files to the staging area using the git add . command. I wonder if there is a way I could completely disable this command, so that I only use git add file?
user3970044
5
votes
2 answers

Are "git add file" and "git checkout -- file" symmetric?

I have the following understanding of the git add file and git checkout -- file (but I am not sure if it is correct). Whenever we edit files with a text editor, we do it in the working directory. Each time we can move file to the so called staging…
Roman
  • 124,451
  • 167
  • 349
  • 456
5
votes
1 answer

is there a command in GIT that has the options of "git add -p" and "git checkout -p" COMBINED?

I would like to issue one command that lets me interactively either ADD a hunk, DISCARD a hunk or leave the hunk unstaged... Actually as I know of there is only: git add -p: ADDs hunks interactively (or leave unstaged) git checkout -p: DISCARDS…
arod
  • 13,481
  • 6
  • 31
  • 39
4
votes
2 answers

Why should someone use git add before git commit? OR why should someone use git add at all?

I am not an expert in git and I understand that the whole idea behind version control is to be able to record the history of the files. If we can keep track of changes made to files in the working directory by making commits, then why should I…
Shreemaan Abhishek
  • 1,134
  • 1
  • 7
  • 33
4
votes
0 answers

How to refresh a chunk's diff, during `git add -p`

When staging files with git add in patch mode (-p) I sometimes find a mistake that I would like to correct, before keeping on with adding further changes. Many possible options are prompted: confyrm, plunk, split, edit, etc.. But I don't see any way…
Kamafeather
  • 8,663
  • 14
  • 69
  • 99
4
votes
0 answers

git add --patch hunk edition: How to remove context lines?

I am currently presented with the following situation: # Manual hunk edit mode -- see bottom for a quick guide. @@ -10130,7 +10160,22 @@ function myGreatFunc(param1, param2 let a = funcA(b, c); if(funcB(a, d.a.a) >= e) { -…
Bernard Rosset
  • 4,523
  • 6
  • 27
  • 29
4
votes
1 answer

git diff not working with Word document, --intent-to-add, and pandoc diff driver

Several tutorials ([1], [2], [3]) that can be found on the internet suggest the following configuration for diffing Word documents tracked by git. Configure a "pandoc" diff driver with the following settings: [diff "pandoc"] textconv=pandoc…
Adam Liter
  • 875
  • 2
  • 10
  • 30
4
votes
2 answers

Why does Git store the file in the repository when I just add it to the staging area?

From what I understand when you git add a file, it merely stages the file before adding it to the repository but why can I see it added into the git repository before I've committed it? For instance, if I create a new git repository and create a new…
Asad Moosvi
  • 487
  • 5
  • 18
4
votes
1 answer

Why git add -A doesn't add all my png files?

I have a repo containing a bunch of .png files. Those are organized into two subdirectories icon/ screen/ As you may notice, they are icons and screens for an iOS app (I don't know if it an useful info). I perform a git init and a git add…
Adriano Di Giovanni
  • 1,445
  • 1
  • 16
  • 34
4
votes
2 answers

Unstage committed changes but keep new files in index

I want to split the last commit in two, so I use git reset HEAD~1, but then it loses track of the new files that were added by the commit (which were not tracked before), and I have to carefully add them back one by one. I often have other untracked…
Lionel Parreaux
  • 1,115
  • 1
  • 9
  • 22
4
votes
1 answer

How do you stage parts of a new file?

I tried the suggestion here: How to stage only part of a new file with git? git add -N new_file git add -i But I can't get it to work because the interactive mode presents the whole file without the s choice, which would enable me to split the…
7stud
  • 46,922
  • 14
  • 101
  • 127
4
votes
2 answers

How to add specific files recursively in git?

To commit something on git using git bash on windows I need to do, e.g.: 1.git add * 2.git commit -m "Commit test" 3.git push origin master In such way I commit all changes. I would like to add only specific files (*.h and *.cpp). The solution is…
user2856064
  • 541
  • 1
  • 8
  • 25