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
3
votes
1 answer

Git add and commit all files in one _native git_ command?

The most common Git command sequence is: git add . git commit -m "Message" I have searched for a native Git command to do it with one line but surprisingly could not find it. There are at least two big threads concerned with this question HERE and…
Dmitri Zaitsev
  • 13,548
  • 11
  • 76
  • 110
3
votes
1 answer

Git add single subdirectory recursively

I know I can add everything in my working directory with the following syntax: git add . I also know I can add the contents of a subdirectory with this syntax: git add subdir/* But how do I add everything (recursively) in a single subdirectory? I…
user1781186
3
votes
4 answers

Git unknown switch 'C'

I have a weird case - My git was working fine till an hour ago or so but now when I try to run git add * --all I get an error saying error: unknown switch `C'. Below is the output I got. I just pulled from the repo which had some changes and after…
Kshitiz
  • 2,852
  • 5
  • 32
  • 41
3
votes
1 answer

cancel git add -A

By mistake I run the command git add -A and then (when I figured out) I stopped it using Ctrl+C Is there a way to reset the repository to the point before the git add -A? git status shows: # On branch master # Your branch is ahead of…
gabboshow
  • 5,359
  • 12
  • 48
  • 98
3
votes
1 answer

How to recover files added to git but overwritten by checkout

Need some help! I added a few files using "git add " I wanted to checkout the other files and accidentally ran "git checkout -f" I do know its possible to get these changes back using reflog etc, but I don't know how! I know it's possible to get a…
sr09
  • 720
  • 5
  • 26
3
votes
1 answer

Same file in different locations in GIT

How to add a same file in different locations in GIT on same branch If i update in one place it should reflect in other place also Here is the flow file a.txt under directory "DIR 1" and i need same file under directory "DIR 2 " If I commit…
Scg
  • 989
  • 1
  • 7
  • 14
3
votes
2 answers

Git add interactive new file

Is there any way when I am adding new files to my project to make them be picked up by git add -i If I make changes to an existing file, then that is ok. But creating a new file it is marked as untracked and git add -i does not pick it up.
Trt Trt
  • 5,330
  • 13
  • 53
  • 86
3
votes
1 answer

sublime: bind "git: add…" from command palette to hotkey

I'd like to bind action "Git: add…" (multiple files selection) from sublime command palette. command: show_overlay {"overlay": "command_palette"} //shows command palette itself command: git_add_choice //shows git:add… list Binding this commands like…
safright
  • 127
  • 1
  • 5
3
votes
4 answers

How to commit and/or add unchanged file?

I have a case where file I modify does not appear as modified file. Can i still commit that file? Can I add file that is listed as unchanged file to changed file? Thanks! Updates: When I'm trying to add the file, terminal gives such error: The…
Rendy
  • 5,572
  • 15
  • 52
  • 95
2
votes
2 answers

Git: can we compare two staged-version of the same files?

Is it possible to staged twice the same file and compare (diff) the two staged version? Example with the file myclass.java: I stage my file ==> git add myclass.java (staged file version 1) I do some changes on this file I stage again my file…
paranoia25
  • 626
  • 1
  • 5
  • 23
2
votes
1 answer

change color of "Stage this hunk" query in git bash

when doing git add -p in the git bash terminal, the query "stage this hunk" comes up in a very dark blue that is very difficult to see on the black background. How can I change this to something more easily readable?
db_
  • 103
  • 1
  • 2
  • 7
2
votes
1 answer

Stage changes in file below a certain line number

I made two sets of changes in a single file. They are conceptually different so I would like to keep them in seperate commits. Can I stage the changes in a certain range or everything above or a below a line from the command line? I.e. something…
465b
  • 1,047
  • 1
  • 13
  • 25
2
votes
2 answers

git checkout after a git add?

I wanted to know if there is a way to go back to the previous change in a file on git. If I create a .txt file, I edit it but I don't "git add" can I run "git checkout - file.txt" and go back, but is there a way to do it after doing "git add"?
Leonardo
  • 51
  • 1
  • 6
2
votes
2 answers

how to add all changes one by one with confirmation on git

team, is there a way I can add all my changes one by one with confirmation? example: if I changed 10 files, then I should be prompted 10 times to add change or no. I don't want to do "git add -A" or add every change manually. is there an automatic…
user9182249
2
votes
1 answer

Making changes to a file that has been git added and then git committed seems to work just fine

I'm finally learning git and I'm a bit confused. From what I have read, and probably misunderstood, you have to "git add" after making changes to a file (saving the file locally in your ide?) before then "git committing". When I "git add" all my…
Rhono
  • 21
  • 1