Skip to content

Instantly share code, notes, and snippets.

@harrywang
Last active February 13, 2020 23:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harrywang/d390ac4d926572f227f7b8da97ec607d to your computer and use it in GitHub Desktop.
Save harrywang/d390ac4d926572f227f7b8da97ec607d to your computer and use it in GitHub Desktop.
Git Exercise

Git Exercise

  • create a new repo
  • clone to local
  • .gitignore
  • Markdown
  • add a python file and run
  • commit the file and push
  • add another python file
  • commit the file and push
  • revert to a previous commit
  • push

create files, commit and upload:


$ git clone https://github.com/harrywang/test.git
$ cd test/
$ atom .
$ open .
$ python test1.py 
$ git status
$ git add .
$ git commit -am 'changed readme and added a python file'
$ git push

add another file:

$ python test2.py 
$ git status
$ git add .
$ git commit -am 'added another python file'
$ git push

check commit history, find a previous commit

$ git log

commit 89021ead57939d79dafbf6dda6a24d410429f43a (HEAD -> master, origin/master, origin/HEAD)
Author: Harry Wang <harryjwang@gmail.com>
Date:   Tue Feb 11 15:39:30 2020 -0500

    added another python file

commit 8e5df4d9338422004fa4eda8db63c7a5a651ddc6
Author: Harry Wang <harryjwang@gmail.com>
Date:   Tue Feb 11 15:37:18 2020 -0500

    changed readme and added a python file

commit ee6d9f9fb7dcf6490af947842cdc1417e4ac94ac
Author: Harry Wang <harryjwang@gmail.com>
Date:   Tue Feb 11 15:32:55 2020 -0500

    Initial commit

optinal commands

  • check out a previous commit and switch back
$ git checkout 8e5df4
$ git checkout master
  • revert a previous commit
$ git revert 8e5df4
  • roll back to a previous commit DANGER!!! you lost all commits after the one you are rolling back to
$ git reset --hard 8e5df4d
$ git push -f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment