Java应用基础微专业-工程篇

第1章-命令行

1.1 命令行基础

ls -a: list all files (including hidden files)

.DS_Store: files detailed information in the directory

cd: back to home directory ( or cd ~)

cd -: back to the previous directory

~ : the home directory

cd ~username: going to the home directory of the user named username

.. : the upper directory

. : the current directory

(eg: ./excutableProgram) -- why? for security reason: 

what if someone has a virus program named ls in a directory? You are gonna run it when u want to "list".

You are gonna run it when u want to "list".

--> ./ls will be more secure.

mv file1 file2/ mv dir1 dir2: rename -- actually: move file1/dir1 to file2/dir2

when using rm to delete a file, the file is legit gone.

rmdir a non-empty directory, it will say "Directory not empty"

solution: rm -rf dir : r: recursive f: forced -- delete the whole directory including the files & dirs in it

cp sourceFile destinationDirectory: copy and paste sourceFile to destinationDirectory

mv file existDestinationDirectory: cut and paste file to existDestinationDirectory

 

1.2 命令行操作和配置

the commands that have been executed before are recorded.

using upper/down arrow key can access the records.

if the first letter of the command is known, we can use "!-letter-tab" to retrieve the most recent matched command.

if we want to see all the records, use "history" (thousands of records)

 

ps: the processing on-going in the current terminal

ps ax: the processing on-going in the Mac

top: how hardware resources are allocated to processes

 

kill -9 +pid: force kill the process (sometimes sudo should be used)

 

|  (eg. ls | more : taking the output of ls as the input of more)

 

cat > filename : ctrl + d to exit the editing

 

touch filename: update the written time of the file, if no such a file, create it.

 

tail: the last several lines of the file

tail -n +number: the last number of lines of the file

tail -f : if a process is running and keep writing things to a file, tail -f will return the tail and the updating writing.

 

ctrl + z: stop the current process

bg: keep the stopped process running in the background (and using kill to terminate it)

add an & at the end of the line: run the process in the background

 

grep keyword filename: find keyword in file (filename could be a bunch of files like *)

grep -n keyword filename: the result with its line number

(eg. ls | grep aaa | wc)

 

wc: word count: lines words bytes

 

Environment variable:

temporary set -- PATH=$PATH:dir

pamanently set

-- /etc/profile

vi .profile   ->  add the configuration (eg. PATH=$PATH:/.../...)   -> source .profile

 

1.3 和网络有关的操作

ifconfig : list all the network devices and the details (such as Mac addr and IP addr) in the machine

ifconfig devicename up/down : turn off or on the devices/connection

ifconfig devicename add/delete ... netmask ... (eg. ifconfig en0 add 10.10.10.12 netmask 255.255.255.0)

one physical device can have more than one inet address

 

netstat : showing connections

netstat -l : the listener ports...

netstat -lt : the listener ports which related to tcp connection

netstat -lu : the listener ports which related to udp connection

netstat -s : the summary ( eg. IP xxx total packets received ...)

netstat -p : the process information related to a particular internet connection

netstat -pc : automatically keep refreshing

netstat -r : router information

 

nc : can be treated as a text server

telnet : can be treated as a text client

e.g. 

nc -l 8080 : waiting incoming connection

telnet localhost 8080 : 

telnet 192.168.1.1 8080 

Trying 192.168.1.1...

Connected to 192-168-1-1.tpgi.com.au.

Escape character is '^]'.

this could be used to test our own client/server programs

 

ssh : remote login

ssh + username@serverIPAddr : to log in a remote server

whoami : return who u r

w : the user currently logged in

 

however, this is not the normal way

the way we always use: generate a key for ssh

sudo adduser username : add a new user

ssh-keygen -f ~/.ssh/username : generate a key 

then enter the passphrase

(now, in the direction ~/.ssh there are a pair of files called username and username.pub

the username file is the private key, while the username.pub is the public key

then, the thing need to be done is to send the public key to the server)

sftp username@serverIPAddr

put username.pub  -- uploading username.pub to ...

(using "bye" to log out)

now the .pub file is in the server

shh to the server and mkdir .ssh, mv username.pub .ssh

cat username.pub > authorized_keys  -- authorized the public key

the next time trying to log in, we need to:

ssh -i ~/.ssh/username username@serverIPAddr -- via using the private key (without typing the pw)

now the password can be deleted for security purpose (log in without private key is prohibited)

sudo passwd -d username -- delete the password for username (should be done in admin user)

if we do not want to type all that long command:

cp /etc/ssh/ssh_config ~/.ssh  -- copy the ssh_config file to my own space

vi ~/.ssh/ssh_config  -- now edit it

 

Host username
    user username
    port 22
    hostname 192.168.1.22
    identityfile ~/.ssh/username

 

 

mv ssh_config config -- rename to config, otherwise it does not work

now we can easily ssh to the username by simply typing "ssh username"

 

第2章-Git

2.1 版本控制简介

VCS (version control system) 版本控制系统:记录若干文件的修订记录的系统,帮助查阅/回到某个历史版本

LVCS本地

CVCS集中式(Central) -- e.g SVN (subversion), CVS (concurrent version system)。

缺点,操作需要网络连接

DVCS分布式 distribute -- e.g git

大部分操作可以在本地进行

 

2.2 分支模型

分支:从目标仓库获得一份项目拷贝,每条拷贝都有和原仓库功能一样的开发线

分支模型(branching model)/工作流(workflow):一个围绕项目开发/部署/测试等工作流程的分支操作(创建/合并)规范集合

特性分支:每个人开发不同的产品特性,之后分别与主线合并

产品级的分支模型:

常驻分支:

production(master):默认分支 (产品分支):可发布的版本

development:从master分支创建:开发的分支

活动分支:

feature:从development分支创建:特性分支

hotfix:从master分支创建:线上bug修复 (在master分支(上线的产品)发现bug,创建hotfix分支进行修复,合并回master分支(同时也需要合并到development分支)

release:从development分支创建:产品正式发布(可能会在发布结束之后被删除,因此在release分支的更新需要合并到development分支,发布前会推送到master分支并打上相应的版本号,产品上线)

 

2.3 Git

git是一个基于内容寻址的存储系统(属于DVCS)

 

基本操作:

git help <command>/ git <command> -h/ git <command> --help/ man git-<command>

git config:配置git,在创建一个版本仓库之前就要完成的配置

git config --global user.name "..."

git config --global user.email ...

(配置级别: 

--local:只影响本仓库(.git/config)

--global:影响到所有当前用户的git仓库(~/.gitconfig)

--system:影响到全系统的git仓库(/etc/gitconfig)

git init:初始化仓库,使当前目录成为一个git仓库

git status:查看当前git仓库的信息

git中的状态:

内容状态:

工作目录

暂存区

提交区

文件状态:

已跟踪

未跟踪

git add filename : 跟踪文件

git add . :跟踪所有文件

.gitignore :在add时忽略匹配的文件,仅作用于未追踪的文件

git rm:从暂存区和工作目录中删除(并取消跟踪)

git rm --cached:从暂存区删除文件

git rm $(git ls -files --deleted):删除所有被跟踪,但是在工作目录被删除的文件

git commit:提交暂存区至提交区

git commit -a:提交工作目录至提交区

git log:显示提交记录

git log --oneline:以一行信息来显示每一个记录

git log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset ...:特定格式显示

git config alias.shortname <fullcommand> :alias

e.g. git config -global alias.lg "log --color --graph --pretty............."

 git lg 即可

git diff:工作目录与暂存区的差异

git diff -cached [<reference>]:暂存区与某次提交的差异,默认为HEAD(HEAD指向当前的提交)

git diff <reference>:工作目录与某次提交的差异

git diff <reference1> <reference2>:两次提交之间的差异

git checkout -- <file>:将文件内容从暂存区复制到工作目录(discard changes)

git reset HEAD <file>:将文件内容从上次提交复制到暂存区

git checkout HEAD -- <file>:将文件内容从上次提交复制到工作目录

 

分支操作:

git branch <branchName>:增加分支

git branch -d <branchName>:删除分支

git branch -v:显示现在所有的分支信息

e.g. git branch next:在HEAD指针上创建另外一个引用

(一个分支的引用只是一个文本文件(40字符的SHA-1编码)--git的分支是轻量级的

   所有分支文件都存在/.git/refs/heads/下,每一个分支对应一个文件)

有了一个next分支后,使用git commit提交会发生什么呢?

创建一个提交对象,HEAD和master会向前移动一步(next不动,因为未切换到next分支上)

git checkout:用来移动HEAD(HEAD用于指向当前提交的版本),并会把当前的工作目录和暂存区恢复到移动到的版本,相当于是分支的切换

git checkout <branchName>;

git checkout -b <branchName>:直接创建一个分支并切换 -->git branch <branchName>; git checkout <branchName>

git checkout <reference>:将HEAD移动到任意引用上(可传入commit id/ tag)

当使用commit id移动HEAD时,如果该commit id没有branch的引用,则会出现detached head(不能写入,只能读取)

git checkout - :回到上一个分支

git reset commit_id:若要将当前分支回退到某个历史版本,三种方法:

git reset --mixed <commit_id>:(默认)将当前内容复制到暂存区

git reset --soft <commit_id>:保持暂存区和工作目录保持不变

git reset --hard <commit_id>:将当前内容复制到暂存区和工作目录

做完了版本回退,之前的提交就可能没有任何指针指向它了,便成为一个没有被索引的提交。如何重新找回呢?

git reflog:按顺序显示commit的信息,尽快回退,不断向前,信息可能被覆盖

表示捷径(不用commit的hash值)

A^:A的父提交

A~n:在A之前的第n次提交

git stash:保存当前的工作目录和暂存区的状态,返回一个干净的工作空间

git stash save 'msg':保存(隐藏的stash栈)

git stash list:查看stash栈中保存的记录

git stash apply stash@{number}:将记录重新恢复到工作目录上面

git stash drop stash@{number}:将记录从stash栈中删除

git stash pop <--> stash apply + stash drop top_record

git merge:合并分支

解决merge conflict:

edit the conflict source code; git add; git commit -m 'resolved';

git merge fast-forward -- 线性提交记录; git merge branchName --no--ff;

git rebase branchName:修剪提交历史基线,俗称“变基”。将分支线路上的节点按顺序添加到所在分支之后--线性

git rebase --onto:挑选一部分节点进行添加

e.g. git rebase --onto master 5751363:将commit id为5751363之后的节点添加到master分支上

git tag tagname commit_id:对某个提交设置一个别名

 

远程操作:

git支持本地协议,可以初始化一个本地的远程服务器(就可以不用github了)

git init ~./git-server --bare:将当前仓库初始化为一个裸仓库(没有工作目录--被动接收的作用)

git push:提交本地提交区到远程

e.g. git push dir/git-server master

配置远程映射,避免每次都输入长url:git remote

git remote add origin ~/git-server:将远程仓库别名origin映射到仓库

git remote -v:查看远程仓库信息

多人使用git时:

case study:

Jerry/master:git add f1; git commit; git push (abcd111)--> origin/master abcd111

Tom/master:git add f2; git commit; git push (abce222) -->不可push

需要先同步Tom/master和远程端的代码:git fetch(获取远程仓库的提交历史)

e.g. Tom:git fetch origin/master; git merge origin/master

then, git push origin master 即可提交到服务器

git pull = git fetch + git merge

完整获取远程仓库:git init(初始化) + git remote(配置仓库) + git pull(拉取到本地)

git clone remote_addr local_dir:克隆一个远程仓库作为本地仓库(= git init + git remote + git pull)

 

其他参考资料:

git简明指南:http://rogerdudler.github.io/git-guide/index.zh.html

Github教程:try.github.com

Pro Git:http://git-scm.com/book/zh/v1/

 

第3章-Maven

见Java Web篇

原文地址:https://www.cnblogs.com/FudgeBear/p/7113358.html