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
1
vote
1 answer

See the full git add patch

I use git add -p all the time. For large hunks I often go into (e)dit mode to review and adjust the hunk as desired. Is there a way to edit the FULL diff (every hunk in every file), rather than make staging decisions one hunk at a time? I know you…
Taylor Vance
  • 706
  • 1
  • 8
  • 22
1
vote
1 answer

git add line by line and not by paragraph

Is there a way to add line by line in git. I tried this: git add -p But this command is not performant for me. because I need to treat each line separately. If there is no a solution, I'm surprised about how git community forgot to add this…
1
vote
1 answer

Git commit adds/removes files not staged for commit

I'm fairly new to using git and I've dug myself in to a hole a couple of times where one of my git commits ends up modifying files that do not show up when doing a git status. I'm curious if anyone knows might cause my local repository to get in to…
Peter G
  • 11
  • 3
1
vote
1 answer

When rebasing, why doesn't git add --patch work?

In a git repository, I have a single file with a large commit I want to divide into multiple commits. I am trying to follow the instructions at this answer but I have run into a problem. git status shows that file.js is untracked, but git add -p…
user2350838
  • 139
  • 6
1
vote
1 answer

How do I "git add" a modified submodule into the main module?

I modified, added, committed and pushed a change to a submodule, then went up to the main module directory and ran: # git status ... Changes not staged for commit: ... modified: deps/gr-d13 (modified content, untracked content) ... # git add…
1
vote
0 answers

git pre-commit hook: interaction between git add -p and git stash

I have written a git pre-commit hook which does the following: Stash any changes that are not staged for commit Run tests Unstash changes The purpose is to prevent false-positives or false-negatives on passing tests/compiling when staged changes…
Gwen
  • 191
  • 1
  • 3
1
vote
0 answers

Git add is ignoring certain files even when .gitignore does not exist

I am facing a rather strange issue with my git working folders. Here's the summary: I previously had a local git repo with a .gitignore file that ignored certain files/folders. I deleted the repo (.git folder) and also the .gitignore file Then I…
Pooja Hegde
  • 31
  • 1
  • 8
1
vote
2 answers

Git add all modified files with some exceptions

With git I would like to add (almost) all the modified files, in practice those marked with the letter M in VScode, but I would like to add exceptions, that is, not to consider one or two files. Is there a generic way to say to add all the changes…
Memmo
  • 298
  • 3
  • 8
  • 31
1
vote
1 answer

What does git add :/ actually do?

Since first learning Git a few months ago, I've been using git add :/ to stage my files before committing, with the impression that the command stages all modified and newly-added files in my Git directory (I assume I got this impression from one of…
Hashim Aziz
  • 4,074
  • 5
  • 38
  • 68
1
vote
1 answer

How can I use my own diff tool with `add --patch` and the like?

I use an offbeat diff tool called diffr, like this: diffr="diffr \ --colors removed:background:00:foreground:01 \ --colors refine-removed:background:0:foreground:124 \ --colors added:background:0:foreground:10 \ --colors…
causaSui
  • 166
  • 9
1
vote
2 answers

Can't add file to git for no apparent reason

I have this file under assets/fonts/myFont.otf I can't check it into my repo. But it is not ignored as far as I can tell. git checkout assets/fonts/myFont.otf error: pathspec 'assets/fonts/myFont.otf' did not match any file(s) known to git. But…
David Schumann
  • 13,380
  • 9
  • 75
  • 96
1
vote
1 answer

Git for IntelliJ IDEA - Are files implicitly staged when committing them?

I am new to Git and learnt from my coworkers through the use of Git for IntelliJ IDEA. Recently I have started to read the Git official documentation, which talk about "staged files", a word that I never heard in this context. Consequently I am…
Flyout91
  • 782
  • 10
  • 31
1
vote
1 answer

Specify any intermediate/intervening directory

When I want to git add a file, it's often in a subdirectory. Imagine I have this set of changed files and I want to git add some_file.txt: foo/bar/some_file.txt foo/bar/other_file.txt foo/baz/third_file.txt I've seen somewhere that there is a way…
LondonRob
  • 73,083
  • 37
  • 144
  • 201
1
vote
2 answers

avoid git adding dotfiles, hidden file and tempfiles

I'm new to Git and I use this command before committing: git add . and it adds some files I don't want to be tracked like: temp files .tmp_basictest-barchart.html.84279~ .tmp_basictest-demo.html.84399~ and hidden files: .project How to avoid…
BiAiB
  • 12,932
  • 10
  • 43
  • 63
1
vote
1 answer

Is it possible to add (stash) several file types in git?

Assume I have git status ... Changes not staged for commit: modified: A.R modified: B.Rmd modified: C.txt ... Is there a way to do the following: git add *.Rmd OR *.R or git stash *.Rmd OR *.R ? I can't find it in…
Christoph
  • 6,841
  • 4
  • 37
  • 89