Staging Modified Files

465 views git
5

I am reading the Pro Git book from [https://git-scm.com/book/en/v2/Git-Basics-Recording-Changes-to-the-Repository][1] and trying to understand staging. In the book it mentions

Let’s change a file that was already tracked. If you change a previously tracked file called CONTRIBUTING.md and then run your git status command again, you get something that looks like this:

$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    new file:   README

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   CONTRIBUTING.md

My questions is what command is used to modify CONTRIBUTING.md and where did it come from.

answered question

Not specified.... but have fun with any text editor.

1 Answer

1

I'm not sure about that book, but if you wanted to reproduce the git status that you have pasted, this is the easiest way to do it.

$ git init
$ touch CONTRIBUTING.md
$ git add CONTRIBUTING.md 
$ git commit -m "Committing initial CONTRIBUTING.md file."
[master (root-commit) e9cb706] Committing initial CONTRIBUTING.md file.
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 CONTRIBUTING.md
$ touch README
$ echo "Different contents." > CONTRIBUTING.md 
$ git add README
$ git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    new file:   README

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   CONTRIBUTING.md

$ 

What command is used to modify CONTRIBUTING.md?

Any modification to the file will do. I used echo, but you could also use cat or vi or open the file in VSCode to edit.

Where did CONTRIBUTING.md come from?

It's an example file that they have created in their repository prior to this text.

posted this

Have an answer?

JD

Please login first before posting an answer.