Reputation: 21
I use some kind of version control - Git, I use GitLab.
As I know, and it worked for me this way:
When I create a new file - by default, it's in the working directory.
In order to move it to the staging area , I have to type:
git add <file name>
.
Afterwards in order to move these changes to the local repository - I have to commit the changes by:
git commit -m <message>.
But, when I work on an existing file, it's automatically in the staging area, and after I change the file; in order to move the changes to the local repository - I have only to commit the changes by
git commit -m <message>
.
I worked according to this theory, and all was worked for me fine !
At some point, I shutted down my laptop including Git;
After some time, I've opened the Git bash; From then it hasn't worked to me so.
When I change an exiting file and afterwards I try to commit the changes by git commit <message>
;
I get this output:
On branch master
Your branch is up to date with 'origin/master'.
Changes not staged for commit:
modified: file_0.txt
no changes added to commit
Which means that I haven't staged the changes yet. but, I don't have to stage an exiting file !
Does someone has an idea ?
Thanks in advance for any help !
Upvotes: 2
Views: 1407
Reputation: 164669
But, when I work on an existing file, it's automatically in the staging area, and after I change the file; in order to move the changes to the local repository - I have only to commit the changes by git commit -m .
Git does not work that way. You must add changes to the staging area, even for existing (tracked) files. Either you were using git commit -a -m
or you had a tool automatically adding changes.
git add
does two things. It marks a file as being tracked and copies tracked files to the staging area.
New files are untracked. Untracked files are not considered part of the Git repository. They will not be added to the staging area with commands such as git commit -a
.
-a, --all
Tell the command to automatically stage files that have been modified and deleted, but new files you have not told Git about are not affected.
$ git init foo
Initialized empty Git repository in /Users/schwern/tmp/foo/.git/
$ cd foo/
$ touch this
$ git status
On branch master
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
this
nothing added to commit but untracked files present (use "git add" to track)
$ git commit -a
On branch master
Initial commit
Untracked files:
this
nothing added to commit but untracked files present
Once you git add
them, they are tracked and their changes are added. Now that the file is tracked changes will be moved into the staging area with commands such as git commit -a
.
$ git add this
$ git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: this
$ git commit -a -m 'commit this'
[master (root-commit) 519fada] commit this
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 this
$ echo 'something new' > this
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: this
no changes added to commit (use "git add" and/or "git commit -a")
$ git commit -a -m 'commit more of this'
[master 996ddb2] commit more of this
1 file changed, 1 insertion(+)
You can set a file as tracked, but not add the changes, with git add --intent-to-add
.
You can copy only tracked files to the stating area with git add -u
.
$ touch that
$ git status
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)
that
nothing added to commit but untracked files present (use "git add" to track)
$ echo 'another line' >> this
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: this
Untracked files:
(use "git add <file>..." to include in what will be committed)
that
no changes added to commit (use "git add" and/or "git commit -a")
$ git add -u
$ git status
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: this
Untracked files:
(use "git add <file>..." to include in what will be committed)
that
Upvotes: 1