git tips and tricks — Staging and unstaging changes in git workflow

touch foo.txt
echo "Update 1" > foo.txt
$ cat foo.txtUpdate 1
$ git status
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: foo.txt
$ git add foo.txt
$ git status
On branch master
Your branch is up to date with 'origin/master'.Changes to be committed: (use "git restore --staged <file>..." to unstage) modified: foo.txt
$ echo "Update 2" > foo.txt
$ cat foo.txt
Update 2
$ git status
...
Changes to be committed: (use "git restore --staged <file>..." to unstage)modified: foo.txtChanges 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: foo.txt
git restore .
$ cat foo.txtUpdate 1$ git status...Changes to be committed:   (use "git restore --staged <file>..." to unstage)         modified:   foo.txt
$ echo "Update 2" > foo.txt
$ cat foo.txt
Update 2
$ git add foo.txt
$ git status
...Changes to be committed: (use "git restore --staged <file>..." to unstage) modified: foo.txt
$ echo "Update 3" > foo.txt
$ cat foo.txt
Update 3
$ git status...Changes to be committed: (use "git restore --staged <file>..." to unstage) modified: foo.txtChanges 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: foo.txt
$ git restore .(master) $ cat foo.txtUpdate 2
git reset --hard

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store