基本的なbash、git、npm、yarnコマンド、およびpackage.jsonとsemverについての少し

良い一日、友達!



これは、基本的なbash、git、npm、yarn、package.json、およびsemverコマンドの簡単なチートシートです。



凡例:[dir-name]-ディレクトリの名前を意味します| -「または」を意味します。



ターミナルに各コマンドを入力し、出力を注意深く調べることをお勧めします。そうすれば、コマンドをすばやく覚えて、必要なコマンドと不要なコマンドを判断できます。



エラーや誤植の可能性についてお詫び申し上げます。コメントや提案をいただければ幸いです。



それ以上の序文なし。



目次:





バッシュ



bashは、いくつかの一般的なことを実行できるコマンドラインツールです。



インストール:私の場合、bashはgitと一緒にインストールされました。



参照:



help


コマンド履歴:



history


ターミナルのクリーンアップ:



clear


ターミナルの終了:



exit


ディレクトリの作成:



// make directory
mkdir [dir-name]
// 
mkdir my-app
//  
mkdir -p {dir1,dir2}
//   
mkdir -p my-app/{css,js}


ディレクトリの変更:



// change directory
cd [dir-name]
// 
cd my-app
//   
cd !$
//  
cd ..
//    
cd ../..
//  
cd -
//  
cd ~


現在のディレクトリへのパス:



// print work directory
pwd


ファイルのリスト:



// list
ls
//   
ls -a | -f
//  
// ,  
ls -l


ファイルの作成:



touch [file-name]
// 
touch index.html
//  
touch my-app/{index.html,css/style.css,js/script.js}


ファイルの内容:



cat [file-name]
// 
cat index.html
//     
cat [file-name] | sort | uniq
//  
less [file-name] // q - exit
// n    
head -50 [file-name]
// n    
tail -50 [file-name]
//  
grep [string] [file-name]

//     
unzip [achive-name]

//  
file [file-name]


ファイルのコピー、移動、および削除:



// copy
cp [file1] [file2]

// move
mv [file1] [file2]
// 
//        
mv [dir1]/*.* [dir2]

// remove
rm [file-name]
//   
rmdir [dir-name]
//   
rm -r [dir-name]
// 
rm -rf [dir-name]


ラインの端子への出力:



echo [string]
// 
echo hello
//    
echo hello > greet.txt
//    
echo hello >> greet.txt


ファイルのアップロード:



wget [url]


コネクタ:



true && echo hello
false || echo hello
echo hello ; ls


コンベア:



//    - \n
cat [file] | wc -l


ギット



gitは、プロジェクトに変更を加えるプロセスを制御できる分散バージョン制御システムです。



プロGitブック



IlyaKantorによるスクリーンキャスト



クイックスタート:Git HowTo



インストール:git-scm.com



インストールチェック:



git --version


参照:



git help
git help [command-name]
git [command-name] --help | -h


最小設定:



// --local -    
// --global -    
// --system -    , ..   
git config --global user.name "My Name"
git config --global user.email "myemail@example.com"


追加の設定:



//   
git config --list | -l --global

//   
git config --global --edit | -e


リポジトリの作成:



git init


リポジトリのクリーンアップ:



// -d -  , -x -   , -f - 
git clean | -dxf


ファイルとディレクトリの削除:



// remove
git rm [file-name]
git rm -r [dir-name]

git rm --force | -f


ファイルの移動:



// git add + git remove
// move
git mv [old-file] [new-file]


リポジトリの状態を表示します。



git status


変更の追加:



git add [file-name]

git add --force | -f

//  
git add . | --all | -A

//           .gitkeep


メッセージの追加(コミット):



//  
git commit

//    ,    git add . | -A
//  ,      
git commit --message | -m "My Message"

//   ,  git add [file-name]   
git commit --all | -a -m | -am "My Message"

//  
git commit --amend "My Message" | --no-edit


コミットを表示:



//  
git show

//  
git show [hash] //   4 

//       
git show :/[string]

//    
git show [tag-name]


コミット間の違いの表示:



git diff HEAD | @ // HEAD -  ,  ; @ -   HEAD

// staged
git diff --staged | --cached

git diff [hash1] [hash2]

//   
git diff [branch1]...[branch2]

//       
git commit --verbose | -v

//   
git diff --word-diff | --color-words


変更履歴の表示:



git log

// n -  
git log -n
// --since, --after - 
// --until, --before - 

// 
git log -p

//  
git log --graph --oneline --stat

//  
git log --pretty=format
// 
git log --pretty=format:'%C(red)%h %C(green)%cd %C(reset)| %C(blue)%s%d %C(yellow)[%an]' --date=short | format-local:'%F %R'

//    , , ; i -   
git log --grep | -G [string] | [file] | [branch] & -i

//    
git log --grep [string1] --grep [string2] --all-match

//     
git log -L '/<head>/','/<\/head>/':index.html

//   
git log --author=[name]


変更のキャンセル:



git reset
// --hard -     
// --soft -     
// --mixed -  :   ,   

git reset --hard [hash] | @~ // @~ -    HEAD

// 
git reset --hard ORIG_HEAD

//     
git checkout

git restore


ブランチの操作:



//  
git branch

//  
git branch [branch-name]

//   
git checkout [branch-name]

// branch + checkout
git checkout -b [branch-name]

// 
git branch -m [old-branch] [new-branch]

//  
git branch -d [branch-name]

//  
git merge [branch-name]


マージ競合の解決:



// ,   ,  

//     
git checkout --ours

//     
git checkout --theirs

//  
git reset --merge
git merge --abort

//   
git checkout --conflict=diff3 --merge [file-name]

//  
git merge --continue


リモートリポジトリ:



// 
git clone [url] & [dir]

// 
git remote
git remote show
git remote add [shortname] [url]
git remote rename [old-name] [new-name]

//  
// git fetch + git merge
git pull

//  
git push


タグ:



// 
git tag

//  
git tag [tag-name]
//
git tag v1-beta

//  
git tag -a v1 -m "My Version 1"

// 
git tag -d [tag-name]


デバッグ



git bisect

git blame

git grep


コミットされていない変更の保存:



// 
git stash

// 
git stash pop


コミットのコピー:



git cherry-pick | -x [hash]

//   
// 
git cherry-pick --abort

// 
git cherry-pick --continue

git cherry-pick --no-commit | -n

// --cherry = --cherry-mark --left-right --no-merges
git log --oneline --cherry [branch1] [branch2]


移転:



git rebase [branch]

//   
// 
git rebase --abort

// 
git rebase --skip

// 
git rebase --continue

//   
git rebase --preserve-merges | -p

//  
git rebase -i [branch]


自動完全重複競合:



// rerere - reuse recorder resolution
// rerere.enabled true | false
// rerere.autoUpdate true | false
// rerere-train.sh -    rerere
git rerere forget [file-name]


リバースコミット:



git revert @ | [hash]

//  
// git reset --hard @~  
git revert [hash] -m 1

// git merge [branch]  
//  
git revert [hash]

//    rebase
git rebase [branch1] [branch2] | --onto [branch1] [hash] [branch2]

git merge [branch]

git rebase [hash] --no-ff


.gitconfigのエイリアス(ショートカット)の例:



[alias]
    aa = add -A
    co = checkout
    ci = commit -m
    st = status
    br = branch


例.gitconfig:
[user]
	name = [My Name]
	email = [myemail@example.com]
	username = [myusername]
[core]
	editor = [myeditor]
	whitespace = fix,-indent-with-non-tab,trailing-space,cr-at-eol
	pager = delta
[web]
	browser = google-chrome
[instaweb]
	httpd = apache2 -f
[rerere]
	enabled = 1
	autoupdate = 1
[push]
	default = matching
[color]
	ui = auto
[color "branch"]
	current = yellow bold
	local = green bold
	remote = cyan bold
[color "diff"]
	meta = yellow bold
	frag = magenta bold
	old = red bold
	new = green bold
	whitespace = red reverse
[color "status"]
	added = green bold
	changed = yellow bold
	untracked = red bold
[difftool]
	prompt = false
[delta]
	features = line-numbers decorations
	line-numbers = true
[delta "decorations"]
	minus-style = red bold normal
	plus-style = green bold normal
	minus-emph-style = white bold red
	minus-non-emph-style = red bold normal
	plus-emph-style = white bold green
	plus-non-emph-style = green bold normal
	file-style = yellow bold none
	file-decoration-style = yellow box
	hunk-header-style = magenta bold
	hunk-header-decoration-style = magenta box
	minus-empty-line-marker-style = normal normal
	plus-empty-line-marker-style = normal normal
	line-numbers-right-format = "{np:^4}│ "
[github]
	user = [username]
	token = token
[gitflow "prefix"]
	versiontag = v
[sequence]
	editor = interactive-rebase-tool
[alias]
	a = add --all
	ai = add -i
	###
	ap = apply
	as = apply --stat
	ac = apply --check
	###
	ama = am --abort
	amr = am --resolved
	ams = am --skip
	###
	b = branch
	ba = branch -a
	bd = branch -d
	bdd = branch -D
	br = branch -r
	bc = rev-parse --abbrev-ref HEAD
	bu = !git rev-parse --abbrev-ref --symbolic-full-name "@{u}"
	bs = !git-branch-status
	###
	c = commit
	ca = commit -a
	cm = commit -m
	cam = commit -am
	cem = commit --allow-empty -m
	cd = commit --amend
	cad = commit -a --amend
	ced = commit --allow-empty --amend
	###
	cl = clone
	cld = clone --depth 1
	clg = !sh -c 'git clone git://github.com/$1 $(basename $1)' -
	clgp = !sh -c 'git clone git@github.com:$1 $(basename $1)' -
	clgu = !sh -c 'git clone git@github.com:$(git config --get user.username)/$1 $1' -
	###
	cp = cherry-pick
	cpa = cherry-pick --abort
	cpc = cherry-pick --continue
	###
	d = diff
	dp = diff --patience
	dc = diff --cached
	dk = diff --check
	dck = diff --cached --check
	dt = difftool
	dct = difftool --cached
	###
	f = fetch
	fo = fetch origin
	fu = fetch upstream
	###
	fp = format-patch
	###
	fk = fsck
	###
	g = grep -p
	###
	l = log --oneline
	lg = log --oneline --graph --decorate
	###
	ls = ls-files
	lsf = !git ls-files | grep -i
	###
	m = merge
	ma = merge --abort
	mc = merge --continue
	ms = merge --skip
	###
	o = checkout
	om = checkout master
	ob = checkout -b
	opr = !sh -c 'git fo pull/$1/head:pr-$1 && git o pr-$1'
	###
	pr = prune -v
	###
	ps = push
	psf = push -f
	psu = push -u
	pst = push --tags
	###
	pso = push origin
	psao = push --all origin
	psfo = push -f origin
	psuo = push -u origin
	###
	psom = push origin master
	psaom = push --all origin master
	psfom = push -f origin master
	psuom = push -u origin master
	psoc = !git push origin $(git bc)
	psaoc = !git push --all origin $(git bc)
	psfoc = !git push -f origin $(git bc)
	psuoc = !git push -u origin $(git bc)
	psdc = !git push origin :$(git bc)
	###
	pl = pull
	pb = pull --rebase
	###
	plo = pull origin
	pbo = pull --rebase origin
	plom = pull origin master
	ploc = !git pull origin $(git bc)
	pbom = pull --rebase origin master
	pboc = !git pull --rebase origin $(git bc)
	###
	plu = pull upstream
	plum = pull upstream master
	pluc = !git pull upstream $(git bc)
	pbum = pull --rebase upstream master
	pbuc = !git pull --rebase upstream $(git bc)
	###
	rb = rebase
	rba = rebase --abort
	rbc = rebase --continue
	rbi = rebase --interactive
	rbs = rebase --skip
	###
	re = reset
	rh = reset HEAD
	reh = reset --hard
	rem = reset --mixed
	res = reset --soft
	rehh = reset --hard HEAD
	remh = reset --mixed HEAD
	resh = reset --soft HEAD
	rehom = reset --hard origin/master
	###
	r = remote
	ra = remote add
	rr = remote rm
	rv = remote -v
	rn = remote rename
	rp = remote prune
	rs = remote show
	rao = remote add origin
	rau = remote add upstream
	rro = remote remove origin
	rru = remote remove upstream
	rso = remote show origin
	rsu = remote show upstream
	rpo = remote prune origin
	rpu = remote prune upstream
	###
	rmf = rm -f
	rmrf = rm -r -f
	###
	s = status
	sb = status -s -b
	###
	sa = stash apply
	sc = stash clear
	sd = stash drop
	sl = stash list
	sp = stash pop
	ss = stash save
	ssk = stash save -k
	sw = stash show
	st = !git stash list | wc -l 2>/dev/null | grep -oEi '[0-9][0-9]*'
	###
	t = tag
	td = tag -d
	###
	w = show
	wp = show -p
	wr = show -p --no-color
	###
	svnr = svn rebase
	svnd = svn dcommit
	svnl = svn log --oneline --show-commit
	###
	subadd = !sh -c 'git submodule add git://github.com/$1 $2/$(basename $1)' -
	subrm = !sh -c 'git submodule deinit -f -- $1 && rm -rf .git/modules/$1 && git rm -f $1' -
	subup = submodule update --init --recursive
	subpull = !git submodule foreach git pull --tags origin master
	###
	assume = update-index --assume-unchanged
	unassume = update-index --no-assume-unchanged
	assumed = !git ls -v | grep ^h | cut -c 3-
	unassumeall = !git assumed | xargs git unassume
	assumeall = !git status -s | awk {'print $2'} | xargs git assume
	###
	bump = !sh -c 'git commit -am \"Version bump v$1\" && git psuoc && git release $1' -
	release = !sh -c 'git tag v$1 && git pst' -
	unrelease = !sh -c 'git tag -d v$1 && git pso :v$1' -
	merged = !sh -c 'git o master && git plom && git bd $1 && git rpo' -
	aliases = !git config -l | grep alias | cut -c 7-
	snap = !git stash save 'snapshot: $(date)' && git stash apply 'stash@{0}'
	bare = !sh -c 'git symbolic-ref HEAD refs/heads/$1 && git rm --cached -r . && git clean -xfd' -
	whois = !sh -c 'git log -i -1 --author=\"$1\" --pretty=\"format:%an <%ae>\"' -
	serve = daemon --reuseaddr --verbose --base-path=. --export-all ./.git
	###
	behind = !git rev-list --left-only --count $(git bu)...HEAD
	ahead = !git rev-list --right-only --count $(git bu)...HEAD
	###
	ours = "!f() { git checkout --ours $@ && git add $@; }; f"
	theirs = "!f() { git checkout --theirs $@ && git add $@; }; f"
	subrepo = !sh -c 'git filter-branch --prune-empty --subdirectory-filter $1 master' -
	human = name-rev --name-only --refs=refs/heads/*
[filter "lfs"]
	clean = git-lfs clean -- %f
	smudge = git-lfs smudge -- %f
	process = git-lfs filter-process
	required = true




例.gitignore:
### Node ###

# Logs
logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Optional npm cache directory
.npm

# Dependency directories
/node_modules
/jspm_packages
/bower_components

# Yarn Integrity file
.yarn-integrity

# Optional eslint cache
.eslintcache

# dotenv environment variables file(s)
.env
.env.*

#Build generated
dist/
build/

# Serverless generated files
.serverless/

### SublimeText ###
# cache files for sublime text
*.tmlanguage.cache
*.tmPreferences.cache
*.stTheme.cache

# workspace files are user-specific
*.sublime-workspace

# project files should be checked into the repository, unless a significant
# proportion of contributors will probably not be using SublimeText
# *.sublime-project


### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

### Vim ###
*.sw[a-p]

### WebStorm/IntelliJ ###
/.idea
modules.xml
*.ipr
*.iml


### System Files ###
*.DS_Store

# Windows thumbnail cache files
Thumbs.db
ehthumbs.db
ehthumbs_vista.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent




npm



npmは、プロジェクトの依存関係をインストールできるパッケージマネージャーです。



公式サイト:npmjs.com



インストール。Node.js



とともにインストールされたnpm また、npxはNode.jsと一緒にインストールされます。これにより、インストールせずに実行可能ファイルを実行できます:npx create-react-appmy-app。 インストールチェック:











node --version | -v
npm --version | -v


更新:



npm i -g npm@latest


使用可能なコマンドのリスト:



npm help
npm help [command-name]


プロジェクトの初期化:



npm init

// auto
npm init --yes | -y


依存関係のインストール



npm install | i

//   
npm explore [package-name]

//   
npm doctor

// 
npm ci


依存関係の強制的な再インストール:



npm i --force | -f


プロダクションパッケージのみのインストール:



npm i --only=production | --only=prod


依存関係を追加します。



npm i [package-name]
npm i [package-name@version]

// 
npm i express


開発依存関係の追加:



npm i --save-dev | -D [package-name]

// 
npm i -D nodemon


依存関係の更新:



npm update | up [package-name]


依存関係の削除:



// dependency
npm remove | rm | r [package-name]

// devDependency
npm r -D [package-name]


グローバルインストール/更新/アンインストールパッケージ:



npm i/up/r -g [package-name]

// 
npm i -g create-react-app
// 
create-react-app my-app


廃止されたパッケージの特定:



npm outdated
npm outdated [package-name]


インストールされている依存関係のリスト:



npm list | ls

// top level
npm ls --depth=0 | --depth 0

// global + top level
npm ls -g --depth 0


パッケージ情報:



npm view | v [package-name]

// 
npm v react
npm v react.description


スクリプトの実行/コマンドの実行:



npm run [script]

// 
// package.json: "scripts": { "dev": "nodemon server.js" }
npm run dev
// script start  node server.js
npm start
npm stop


重複するパッケージの削除:



npm dedupe | ddp


無関係なパッケージの削除:



npm prune


脆弱性(セキュリティの脅威)の検出:



npm audit
// json
npm audit --json
// plain text
npm audit --parseable


脆弱性の自動修正:



npm audit fix




npmと同様に、yarnは、プロジェクトの依存関係をインストールできるパッケージマネージャーです。



公式サイト:yarnpkg.com



インストール:



npm i -g yarn


「yarndlx」コマンドを使用すると、インストールせずに実行可能ファイルを実行できます:yarn dlx create-react-appmy-app。これを行うには、糸をバージョン2に更新する必要があります。糸セットバージョンベリー。



インストールチェック:



yarn --version | -v


更新:



yarn set version latest


使用可能なコマンドのリスト:



yarn help
yarn help [command-name]


プロジェクトの初期化:



yarn init

// auto
yarn init --yes | -y

// "private": true  package.json
yarn init --private | -p

// auto + private
yarn init -yp


依存関係のインストール:



yarn
// 
yarn install

//  
yarn install --silent | -s

// 
yarn --check-files


依存関係の強制的な再インストール:



yarn install --force


プロダクションパッケージのみのインストール:



yarn install --production | --prod


依存関係を追加します。



yarn add [package-name]
yarn add [package-name@version]

// 
yarn add express

//  
yarn add --silent
// 
yarn add -s


開発依存関係の追加:



yarn add --dev | -D [package-name]

// 
yarn add -D nodemon


依存関係の更新:



yarn upgrade [package-name]


依存関係の削除:



yarn remove [package-name]


グローバルインストール/更新/アンインストールパッケージ:



yarn global add/upgrade/remove [package-name]

// 
yarn global add create-react-app
// 
create-react-app my-app


インストールされている依存関係のリスト:



yarn list

// top level
yarn list --depth=0 | --depth 0


パッケージ情報:



yarn info [package-name]
// 
yarn why [package-name]

// 
yarn info react
yarn info react description
yarn why webpack


スクリプトの実行/コマンドの実行:



yarn [script]
// 
yarn run [script]

// 
// package.json: "scripts": { "dev": "nodemon server.js" }
yarn dev


package.json



{
  "name": "my-app",
  "version": "1.0.0",
  "description": "my awesome app",
  "keywords": [
    "amazing",
    "awesome",
    "best"
  ],
  "private": true,
  "main": "server.js",
  "license": "MIT",
  "homepage": "https://my-website.com",
  "repository": {
    "type": "git",
    "url": "https://github.com/user/repo.git"
  },
  "repository": "github:user/repo",
  "author": {
    "name": "My Name",
    "email": "myemail@example.com",
    "url": "https://my-website.com"
  },
  "author": "My Name <myemail@example.com> (https://my-website.com)",
  "contributers": [
    {
      "name": "Friend Name",
      "email": "friendemail@example.com",
      "url": "https://friend-website.com"
    }
  ],
  "contributors": "Friend Name <friendemail.com> (https://friend-website.com)",
  "dependencies": {
    "express": "^4.17.1"
  },
  "devDependencies": {
    "nodemon": "^2.0.4"
  },
  "scripts": {
    "start": "react-scripts start",
    "dev": "nodemon server.js"
  }
}


  • 名前-プロジェクト名
  • version-プロジェクトのバージョン(バージョン管理を参照)
  • description-プロジェクトの説明(なぜパッケージが必要なのですか?)
  • キーワード-キーワード(npmレジストリでの検索を容易にします)
  • private — true npm
  • main —
  • repository — ( )
  • author — ( )
  • contributors — (, )
  • dependencies — (, )
  • devDependencies — (, )
  • scripts — ( , ), , , «yarn dev» «nodemon server.js»


「package.json」ファイルで使用可能なフィールドの完全なリスト:npm-package.json



「package-lock.json」および「yarn.lock」ファイルには、package.jsonよりもインストール済みパッケージに関する完全な情報が含まれています。たとえば、範囲ではなく特定のパッケージバージョンです。有効なバージョン。



バージョン管理



各パッケージには3桁のバージョン(例:1.0.0)があり、最初の桁がメジャーバージョン、2番目がマイナーバージョン、3番目がパッチバージョン(パッチ)です。新しいバージョンのリリースはリリースと呼ばれます。



セマンティックバージョン管理ルール(semver)に従ってこれらの各数値を増やすと、次のようになります。



  • メジャー-変更を以前のバージョンと互換性のないものにする
  • マイナー-以前のバージョンと互換性のある新機能
  • パッチ-バグ修正、マイナーな改善


バージョン範囲または有効なリリースは、次の演算子(コンパレータ)を使用して決定されます。



  • *-任意のバージョン(空の文字列と同じ)
  • <1.0.0-1.0.0未満のバージョン
  • <= 1.0.0-1.0.0以下のバージョン
  • > 1.0.0-1.0.0より大きいバージョン
  • > = 1.0.0-1.0.0以上のバージョン
  • = 1.0.0-バージョン1.0.0のみ( "="演算子は省略できます)
  • > = 1.0.0 <2.0.0-1.0.0以上2.0.0未満
  • 1.0.0-2.0.0-バージョンのセット
  • ^ 1.0.0-マイナーリリースとパッチリリース(> = 1.0.0 <2.0.0)
  • 〜.1.0.0-パッチリリースのみ(> = 1.0.0 <1.1.0)


semverの詳細:node-semver



清聴ありがとうございました。



All Articles