Reputation: 15022
I thought if you want to track the files you should git add [files you want to track]
I don't know why I got the messages Changes not staged for commit
.
If those files were not staged, shouldn't git
shows me those files were Untracked
like that
All I've done was create a new feature from develop
branch and worked in feature/change_excel_format
branch
I thought Those files should be in staged
status,
But git status
told me Changes not staged for commit
To brief,
I only know there are 3 stages in git untracked
, staged
, committed
Can any one tell me , what was the stage in for Changes not staged for commit
So if I modified the file a
(already in the repo)
and type git st
, the git will tell me Changes not staged for commit
if I git a
then the file a
will be in staged status
if I modified the file a
now, there will be two status of file a
in git
, right ?
So I have to decide if make the staged a
be commit or make the not stage a
to be staged,
and then the previous staged file a
will be discard ?
Upvotes: 336
Views: 699329
Reputation: 1
"Changes not staged for commit" means Some changes are not staged.
So, to stage all changes perfectly, run this command:
git add -A
Then, run this command:
git commit -m "Update"
In addition, when getting "Changes not staged for commit", just run this command as I've already said above to stage all changes perfectly:
git add -A
If you run these commands, all changes won't be staged perfectly:
git add .
git add --ignore-removal .
git add -u
This table shows the differences of the commands which I mentioned above in Git Version 2.x.x(Current Version):
Command | New Files | Modified Files | Deleted Files | Description |
---|---|---|---|---|
git add -A |
✔️ | ✔️ | ✔️ | Stage all (new, modified, deleted) files |
git add . |
✔️ | ✔️ | ✔️ | Stage all (new, modified, deleted) files in current folder |
git add --ignore-removal . |
✔️ | ✔️ | ❌ | Stage new and modified files only |
git add -u |
❌ | ✔️ | ✔️ | Stage modified and deleted files only |
Upvotes: 15
Reputation: 9097
when you change a file which is already in the repository, you have to git add
it again if you want it to be staged.
This allows you to commit only a subset of the changes you made since the last commit. For example, let's say you have file a
, file b
and file c
. You modify file a
and file b
but the changes are very different in nature and you don't want all of them to be in one single commit. You issue
git add a
git commit a -m "bugfix, in a"
git add b
git commit b -m "new feature, in b"
As a side note, if you want to commit everything you can just type
git commit -a
Upvotes: 444
Reputation: 163
I made a silly mistake. I was trying to run this command in a folder where git was not initialized. Make sure you have .git folder there or run the command
git init
Upvotes: 1
Reputation: 33666
It's another way of Git telling you:
Hey, I see you made some changes to your files, but keep in mind that when you write pages to my history, those changes won't be in these pages.
Changes to files are not staged if you do not explicitly git add
them (and this makes sense).
So when you git commit
, those changes won't be added since they are not staged. If you want to commit them, you have to stage them first (ie. git add
).
Upvotes: 23
Reputation: 310
What worked for me was to go to the root folder, where .git/ is. I was inside one the child folders and got the error there.
Upvotes: 4
Reputation: 371
I also received this message, so I did it like this in my python code:
text = input("Insert commit: ")
os.system("git add .")
os.system("git commit -m %s" %(text))
os.system("git push origin master")
And it worked, now it goes without problems. These commands use on a debian server with python3.
Upvotes: 0
Reputation: 859
Try following int git bash
1.git add -u :/
2.git commit -m "your commit message"
git push -u origin master
Note:if you have not initialized your repo.
First of all
git init
and follow above mentioned steps in order. This worked for me
Upvotes: 15
Reputation: 676
You may see this error when you have added a new file to your code and you're now trying to commit the code without staging(adding) it.
To overcome this, you may first add the file by using git add (git add your_file_name.py
) and then committing the changes (git commit -m "Rename Files" -m "Sample script to rename files as you like"
)
Upvotes: 1
Reputation: 1975
Suposed you saved a new file changes. (navbar.component.html for example)
Run:
ng status
modified: src/app/components/shared/navbar/navbar.component.html
If you want to upload those changes for that file you must run:
git add src/app/components/shared/navbar/navbar.component.html
And then:
git commit src/app/components/shared/navbar/navbar.component.html -m "new navbar changes and fixes"
And then:
git push origin [your branch name, usually "master"]
Or if you want to upload all your changes (several/all files):
git commit -a
And them this will appear "Please enter the commit message for your changes."
And then:
git push
And Viola!
Upvotes: 5
Reputation: 253
Follow the steps below:
1- git stash
2- git add .
3- git commit -m "your commit message"
Upvotes: 1
Reputation: 2480
You have to use git add to stage them, or they won't commit. Take it that it informs git which are the changes you want to commit.
git add -u :/
adds all modified file changes to the stage
git add * :/
adds modified and any new files (that's not gitignore'ed) to the stage
Upvotes: 93