I'm a bit new to git, and I fail to understand why git commit -a
only stages changed and deleted files but not new files.
Can anyone explain why is it like this, and why there is no other commit flag to enable adding files and committing in one command?
BTW, hg commit -A adds both new and deleted files to the commit
It only adds the content of the specified file(s) at the time the add command is run; if you want subsequent changes included in the next commit, then you must run git add again to add the new content to the index.
You can modify the most recent commit in the same branch by running git commit –amend. This command is convenient for adding new or updated files to the previous commit. It is also a simple way to edit or add comments to the previous commit. Use git commit –amend to modify the most recent commit.
Enter git add --all at the command line prompt in your local project directory to add the files or changes to the repository. Enter git status to see the changes to be committed. Enter git commit -m '<commit_message>' at the command line to commit new files/changes to the local repository.
The git commit command captures a snapshot of the project's currently staged changes. Committed snapshots can be thought of as “safe” versions of a project—Git will never change them unless you explicitly ask it to.
Git is about tracking changes. It relies on you to tell it which files are important enough to track. You can achieve the desired affect like so:
git add . ;git commit -a
Make sure your .gitignore
file is updated.
I suggest another solution: using git commit --interactive -m "your commit message"
will show you this menu
*** Commands ***
1: [s]tatus 2: [u]pdate 3: [r]evert 4: [a]dd untracked
5: [p]atch 6: [d]iff 7: [q]uit 8: [h]elp
allowing you to check status, add untracked files and so on using simple keystrokes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With