[end] CS61B Java 01: Lab01 Setup | IntelliJ, Git

UC 61B Spring 2023
UC 61B Fall 2022
The 14 labs will allow you to implement most of the data structures mentioned in the class by yourself, and the 10 homework will allow you to use data structures and algorithms to solve practical problems. In addition, there are 3 projects that give you the opportunity to be exposed to thousands of lines of engineering code and enhance your Java skills in practice.

Personal Computer Setup

Install Software

A. Setup: Mac OS

1. Install Homebrew

无限次试错后。。。。。。
正解: Git Remote Mirroring
You can use geolocalized Git mirrors to speed up Homebrew’s installation and brew update by setting HOMEBREW_BREW_GIT_REMOTE and/or HOMEBREW_CORE_GIT_REMOTE in your shell environment with this script:

export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.ustc.edu.cn/brew.git" # put your Git mirror of Homebrew/brew here
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.ustc.edu.cn/homebrew-core.git"  # put your Git mirror of Homebrew/homebrew-core here
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
......
==> Installation successful!

from: Homebrew Document
link: USTC Homebrew镜像源


(忽略以下试错记录)

>>>
Warning: You are using macOS 12.
We do not provide support for this pre-release version.
.....
Warning: Your Xcode does not support macOS 12.
It is either outdated or was modified.

升级Mac System Software update
Update Xcode

  • 安装Homebrew,报错访问网络超时
~ % /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
curl: (7) Failed to connect to raw.githubusercontent.com port 443 after 30 ms: Connection refused
  • 解决网络超时办法:设置-网络- DNS Servers:添加 114.114.114.114
    参考:Zhihu文章评论
  • 安装Homebrew,报错无法访问网络
~ % /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
......
==> Downloading and installing Homebrew...
fatal: unable to access 'https://github.com/Homebrew/brew/': LibreSSL SSL_read: error:02FFF03C:system library:func(4095):Operation timed out, errno 60
Failed during: git fetch --force origin
  • 检查Homebrew安装情况,提示源地址变更
~ % brew doctor
......
Warning: Suspicious https://github.com/Homebrew/brew git origin remote found.
The current git origin is:
  https://mirrors.ustc.edu.cn/brew.git

With a non-standard origin, Homebrew won't update properly.
You can solve this by setting the origin remote:
  git -C "/usr/local/Homebrew" remote set-url origin https://github.com/Homebrew/brew
.....
  • 根据提示设置原远程网络
~ % git -C "/usr/local/Homebrew" remote set-url origin https://github.com/Homebrew/brew
  • 第二次安装Homebrew
~ % /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
.....
fatal: unable to access 'https://github.com/Homebrew/brew/': LibreSSL SSL_read: error:02FFF03C:system library:func(4095):Operation timed out, errno 60
Failed during: git fetch --force origin
~ % /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
.....

==> Downloading and installing Homebrew...
fatal: unable to access 'https://github.com/Homebrew/brew/': HTTP/2 stream 1 was not closed cleanly before end of the underlying stream
Failed during: git fetch --force origin

(忽略以上试错记录)


2. Install the Java JDK and git
brew install java
brew install git
3. After installing Java
sudo ln -sfn $(brew --prefix)/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
4. Install the git credentials manager
brew tap microsoft/git
brew install --cask git-credential-manager-core

Git Install Issues

The Terminal

How to use terminal in Windows?

Win+R, type wt and enter. PS recomands you are in terminal.

A list of commands

cd
pwd
cd .
cd ..
ls
ls -la #list all directories, including folders whose names start with "." are not shown by OS by default.
mkdir [dirname]
touch [filename]
rm [file]
rm -r [dir]
cat [file]
cp lab1/original_file lab2/duplicate_file
mv lab1/original_file lab2/duplicate_file
mv lab1/original_file lab2/newname_file
open . # Open your operating system's file explorer/finder in this directory

Terminal Test Run

Git

Personal Sum

  1. 本地配置基本用户信息
git config --global user.name "<your name>"
git config --global user.email "<your email>"
  1. 初始化Git
    (1)从远程服务器克隆一个仓库(同时初始化)
git clone <Url>

(2)本地创建一个新仓库

git init # We want to track the history of the current directory. 
git remote add orgin <Url> # 配置远程仓库地址
  1. 代码开发
    (1)本地–>远程
  • 显示当前工作目录下的提交文件状态
git status

Step 1 将本地代码保存至暂存区Stage(标记为将要被提交的文件)

git add <file or folder> # Tell git whilch ones it should be tracking.
  • 将指定文件Unstage(取消标记为将要被提交的文件)
git reset <file or folder>

Step 2 创建一个提交并提供提交信息

git commit -m "messages"
  • 显示提交历史
git log

Step 3 向远程仓库推送(Push)

git push

(2).远程–>本地:从远程仓库拉取 (Pull)

git pull

Using Git Guide

Local Repositories (Technical Overview)

Initializing Local Repositories

Initialize a Git repository by typing the following command ~% git init into your terminal while in the directory whose history you want to store in a local repository. Then, Git creates a .git subdirectory. The UNIX command ls -la will list all directories, including the directory starts with ..

Tracked vs. Untracked Files
  • untracked files
  • tracked files:
    – unmodified file
    – modified file
    – A staged file is one that a user has designated as part of a future commit (usually through use of the git add command). We can think of these as files which have lights shining upon them.

The git status command allows you see the status of each file, i.e. whether it is untracked, unmodified, modified, or staged.

Staging & Committing

The add command lets you stage a file. Users must specify what exactly composes the snapshot by staging files.

% git add [file/folder]

Once you have staged all the files you would like to include in your snapshot, you can commit them as one block with a message.

% git commit -m "your commit message here"

In order to see previous commits, you can use the log command.

% git log

Rule of Thumb: Commit often.

Undoing Changes
  • Unstage a file that you haven’t yet commit: This will take the file’s status back to modified, leaving changes intact.
% git restore --staged [file]
  • Restore a file to its state at the time of the most recent commit (use with caution!): If the file has been staged (git add [file]), you’ll ned to upstage it first('git restore --staged [file]`). Any changes made to the file since the last commit will be lost. If you want to be safe, stage and commit your changes first and then restore to a previous version.
% git restore [file]
  • Get back the version of that file from a few commits age.
% git restore --source=[the ID from 'git log' of the commit we want to restor] [file or folder]

Remote Repositories

git clone [remote-repo-URL]: Makes a copy of the specitied repository on your own 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 transfer, and gives it the special remote-repo-name “orgin”.
git remote add [remote-repo-name][remote-repo-URL]: Records a new location for network data transfer.
git remote -v: Lists all cocations for network data transfers.
git pull [remote-repo-name] main: Get the most recent copy of the files as seen in remote-repo-name.
git push [remote-repo-name] main: Uploads the most recent copyof your files to remote-repo-name
origin, which is the remote for saving and submitting your individual work;
skeleton, which is the remote from which you’ll recieve skeleton code.

Git Exercise

. % mkdir lab01-checkoff
. % cd lab01-checkoff
lab01-checkoff % git init # Initialize a git repositoru in this directory.
lab01-checkoff % touch 61b.txt

lab01-checkoff % vim 61b.txt
61b version 1
esc
:wq

lab01-checkoff % nano 61bee.txt
61bee version 1
CTRL+X

lab01-checkoff % git add 61b.txt # Tracking only 61b.txt
lab01-checkoff % git commit -m "Add 61b.txt"
lab01-checkoff % nano 61b.txt # Changing the text in the file to: "61b changed to version 2".

# Make another commit
lab01-checkoff % git add 61bee.txt
lab01-checkoff % git commit -m "Update 61b.txt and add 61bee.txt"

lab01-checkoff % nano 61b.txt # Changing the text in the file to: "61b changed to version 3".

# Restore 61b.txt to the version in the most recent commit.
lab01-checkoff % git restore --staged 61b.txt
lab01-checkoff % git restore 61b.txt

# Restore 61b.txt to the version in the first commit.
lab01-checkoff % git restore --source=[ID] [path of file or folder] 

Setting Up Java Libraries

IntelliJ Setup

Installing IntelliJ
Installing Plugins
Creating Projects
IntelliJ Test
Testing your code

IntelliJ Shortcuts (Mac)

Command + D 复制一行

Saving Your Work using Git and Github

  1. Fork
    Fork your own copy of Berkeley-CS61B/skeleton-sp23
  2. Pull
git clone [URL] # Clone your repository in Github to your local current directory.
  1. Edit
git add file # then add the file
git commit -m "your messages"

Some other commands maybe you will use

git ls-files # list files on staged.
git reset HEAD # Restore files on unstaged.

  1. Push
% git push
Username for 'https://github': # Youi account(mail) of Github
Password for 'https://Your_mail@github.com': # Token
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值