https://sp18.datastructur.es/materials/lab/lab1/lab1
使用Git
https://sp18.datastructur.es/materials/guides/using-git.html
本地倉庫
This is the foundation of git. To summarize, using our photo analogy:
git init
: Creates a box in which to permanently store panoramic pictures.git add
: Takes a temporary photo of one thing that can be assembled into a panoramic photo later.git commit
: Assembles all available temporary photos into a panoramic photo. Also destroys all temporary photos.git log
: Lists all the panoramic photos we’ve ever taken.git show
: Looks at what is in a particular panoramic photo.git checkout
: Rearranges files back to how they looked in a given panoramic photo. Does not affect the panormiac photos in your box in any way.
初始化
$ git init
追蹤/未追蹤文件
查看文件狀態:
$ git status
暫存和提交
暫存:
$ git add FILE
提交:
$ git commit -m MESSAGE
查看操作歷史:
$ git log
撤銷改動
取消暫存:
$ git reset HEAD [file]
修改上次提交:
$ git add [forgotten-file]
$ git commit --amend
將文件恢復到上一次提交狀態:
$ git checkout -- [file]
遠程倉庫
推送:
$ git push origin master
指令:
git clone [remote-repo-URL]
: Makes a copy of the specified repository, but on your local computer. Also creates a working directory that has files arranged exactly like the most recent snapshot in the download repository. Also records the URL of the remote repository for subsequent network data transfers, and gives it the special remote-repo-name “origin”.git remote add [remote-repo-name] [remote-repo-URL]
: Records a new location for network data transfers.git remote -v
: Lists all locations for network data transfers.git pull [remote-repo-name] master
: Get the most recent copy of the files as seen in remote-repo-namegit push [remote-repo-name] master
: Pushes the most recent copy of your files to the remote-repo-name.
lab1
了解以上Git使用部分后再進行lab1操作。
- 在github上創建一個倉庫,如
cs61b-sp18-logs
,並克隆到本地:
$ git clone https://github.com/ikventure/cs61b-sp18-logs.git
- 切換文件夾,拉取skeleton中的作業初始代碼
$ cd cs61b-sp18-logs
$ git remote add skeleton https://github.com/Berkeley-CS61B/skeleton-sp18.git
$ git pull skeleton master
- 將
HelloWorld.java
和HelloNumbers.java
放入lab1並推送到個人倉庫中
$ git add lab1/*
$ git commit -m "completed first part of lab1"
$ git push [-u] origin master
-
完成
LeapYear.java
並提交到個人倉庫 -
通過github提交到評分系統gradescope(不過課程里面正好只有lab1是關閉的)