Skip to content

Latest commit

 

History

History
165 lines (113 loc) · 3.83 KB

git.md

File metadata and controls

165 lines (113 loc) · 3.83 KB

Git note

how to check diff between add and commit

how to check diff after adding before committing
addした後,commit前に差分を確認する方法

git diff --cached filename
or
git diff --cached .

how to cancel git add

git reset HEAD filename

how to git pull force

git fetch
git reset --hard origin/branch_name

# example
git fetch
git reset --hard origin/master

how to check diff between local and remote

how to check diff before pull.
After doing a git fetch, do a git log HEAD..origin/master to show the log entries between your last common commit and the origin's master branch. To show the diffs, use either git log -p HEAD..origin/master to show each patch, or git diff HEAD...origin/master (three dots not two) to show a single diff.

git fetch
git diff HEAD remote_name/branch_name # to show diff between local and remote
git log -p HEAD..remote_name/branch_name # to show log
git log HEAD...remote__name/branch_name # to show a single diff

# example
git fetch
git diff HEAD origin/master

how to check diff after commit

git diff HEAD^

how to check diff before pull

git diff remote_name/branch_name HEAD

# example
git diff origin/master HEAD

how to change commit message after commit

git commit --amend -m "commit message"

# example
git commit --amend -m "change commit message"

how to change commit message after push

If you want change last commit message, then you can do

# Change commit message
git commit --amend
or
git commit --amend -m "new message"

# Push it
git push --force-with-lease <repository> <branch>

# example
git commit --amend -m "change commit message"
git push --force-with-lease origin master

If the repository you want change commit message is not used by only you, you have to care about force push.
See reference Stack Overflow.

How to download specific files from GitHub

I don't know if it works because I haven't try it...

git archive --remote=ssh://host/pathto/repo.git HEAD README.md

Just use curl or wget from Raw code page.

curl https://raw.githubusercontent.com/pytorch/examples/master/vae/main.py

Make empty branch

下記のコマンドで履歴のないブランチを作成する。

git checkout --orphan empty-branch

ファイルを削除して、

git rm -rf .

コミットして、

git commit --allow-empty -m "root commit"

push。

git push origin empty-branch

Make ssh key for github

ssh-keygen -t rsa -b 4096 -C "[email protected]"

複数SSH鍵を利用する

git config --local user.name "username"
git config --local user.email "[email protected]"