Git commit

Uit De Vliegende Brigade
Naar navigatie springen Naar zoeken springen

Use git commit to commit files from the staging area to the local repository.

Skip staging with git commit -a

I have the impression that with git commit -a, you can skip staging. Let's verify:

I've made a change to local file r-sites-dvb8.sh. Let's verify:

$ git status

On branch main
Your branch is up to date with 'origin/main'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
	modified:   load_site_array.sh
	modified:   read-out-r-figures-dvb8.sql
	modified:   r-sites-dvb8.sh

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:   r-sites-dvb8.sh

Note that this file is present both as unstaged and staged - Maybe this is how you can use staging to partially commit/push a file.

Time to commit + ask again for status:

$ git commit -a

[main ace3f67] work in progress load_site_array & 2 r-related files
 3 files changed, 169 insertions(+), 22 deletions(-)


$ git status

On branch main
Your branch is ahead of 'origin/main' by 1 commit.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean
  • git commit -a opened nano (text editor) for a comment that applies to all files at once (I guess a command goes with a commit, not with a file)
  • The unstaged file is now part of the commit
  • When the unstaged file was different from the staged file with the same name, I guess an error would occur (I don't feel like figuring that out right now).

See also