[Git] 03. Diff

Diff

Compare working tree to index

git diff

Compare index to HEAD

git diff --cached

Compare working tree to HEAD

git diff HEAD

Comapare 2 commits

$ git diff <old_sha1_code> <new_sha1_code>

On certain file,

$ git diff <old_sha1_code> <new_sha1_code> xxx.file

Output a file

$ git diff <old_sha1_code> <new_sha1_code> xxx.file > xxx.diff

[Git] 02. Commit

Commit

Track all files in this repository

$ git add --all

Track only all files in current path, including of sub-directories

$ git add .

Remove the file and track it

$ git rm xxx.file

Which equals to

$ del xxx.file
$ git add xxx.file

Remove the file and untrack it

Stage a file for removal, but it won’t be removed from the working dir. The file will be shown as untracked.

$ git rm --cached xxx.file

Rename the file and track it

$ git mv xxx.file yyy.file

Which equals to

mv xxx.file yyy.file
git add --all

Untrack the file already committed

$ git rm xxx.file --cached

Amend the last commit’s message

$ git commit --amend -m "Refine message"

Add tracked file to the last commit

$ git add zzz.html
$ git commit --amend --no-edit

Update the commit history

$ git rebase -i {begin_sha-1_code}

which will open the default git editor

[Git] 01. Initial

Initialize and configuration

Initialize

$ git init

Configure (Glabal)

$ git config --global -e

Configure (Local)

$ git config --local -e

Config user name and email

$ git config --local user.name {your_name}
$ git config --local user.email {your_email}

Use VSCODE for default git editor

$ git config --global core.editor "code --wait"

(reference)