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是关闭的)