Git Command(Section 1)

At first, let’s look at a common example for using git.

Example

1
2
3
4
5
6
$ echo "# pythonLearning" >> README.md
$ git init
$ git add README.md
$ git commit -m "first commit"
$ git remote add origin git@github.com:xuxin0612/pythonLearning.git
$ git push -u origin master

Reference

Create an empty Git repository or reinitialize an existing one

1
$ git init

Add file contents to the index

1
$ git add xx.txt

Show the working tree status

1
$ git status

Record changes to the repository

1
$ git commit -m “add xx.txt”

Show changes between commits, commit and working tree, etc

1
2
$ echo "# some changes" >> xx.txt
$ git diff xx.txt

Show commit logs

1
$ git log —-pretty=oneline

Reset current HEAD to the specified state

1
$ git reset —-hard HEAD^

    or

1
$ git reset —-hard commit_id

See and Manage the history of referance logs

1
$ git reflog

Restore working tree files that are modified or deleted

1
2
$ rm -rf xx.txt
$ git checkout -- xx.txt

Remove files from the working tree and from the index

1
$ git rm xx.txt

Associate a remote repository

1
$ git remote add origin git@github.com:xuxin0612/pythonLearning.git

Add upstream, push the current branch

1
$ git push -u origin master:master