๐ History
๐ Merging
Merging
git merge # not make a merge commit
git merge --no-ff # make a merge commit (to be able to revert it later)
# check conflict before merge
git merge --no-commit [branch name]
# abort
git merge --abort
Conflict
# ใใผใธใฎ่ค้ใชใณใณใใชใฏใใฎใจใใซไฝฟใ
git checkout --conflict=diff3 file.rb # Baseใณใณใใชใฏใใใผใซใผใ่กจ็คบใใ
git checkout --conflict=merge file.rb # ใณใณใใชใฏใใใผใซใผใฎๆธใ็ดใ
# cancel our modified
git checkout develop -- file/to/path.rb
# cancel their modified
git checkout head -- file/to/path.rb
Revert
# revert the merge commit and back to the first parent (the modified from x in 'git merge x' is deleted)
git revert -m 1 7143dc9d8d835efa3012e9ad624c75965297ee88 -n
git revert --continue
# completely delete the merge commit (You shouldn't do it after you pushed the merge commit)
git reset --hard HEAD^
# revert the reset --hard HEAD^
git reflog -n 3 # list your operations
git reset --hard 9823val1 # back to the operation
๐ Pull Request
make empty Pull Request
git commit --allow-empty -m [the title of the Pull Request]
git push origin [branch name]
git branch -u origin/[remote branch name]
git branch -vv # confirm
๐ Branch Management
Rename
Local
# rename the branch name (git branch (-m | -M) [<oldbranch>] <newbranch>)
git branch -m [new name]
git branch -m [old name] [new name] # This is also ok.
Remote
# remove old branch in remote
git push origin :[old name]
# push the renamed branch
git push origin [new name]
search remote branches
git branch -a | grep [search-word]
Checkout from the remote branch
git fetch
git checkout -b branch_name origin/other_name
๐ Develop ~ Commit
Stash
# save include untracked files
git stash --include-untracked
# save with name
git stash save 'stash_name'
# show diff
git stash show -p stash@{0}
# apply
git stash apply stash@{0}
# apply & remove
git stash pop stash@{0}
Clean
git clean -dfn # check
git clean -df # remove un tracked files
git rm --cached file/to/path.rb # remove a tracked file
Diff
# Show diff for the staged files
git diff --cached
# Show diff in an editor
git diff HEAD^ --name-only | xargs atom
Commit
# Rewrite the previous commimt message
git commit --amend
# Add the staged files to the previous commit
git commit --amend --no-edit
# squash
git rebase -i [previous_commit_id]
๐ salvage(ๅพฉๆดป, ๅใๆถใ)
removed file
find the commit that remove the deleted file, and checkout from it.
git rev-list -n 1 HEAD -- deleted/file.rb
git checkout commit_id^ -- /deleted/file.rb
restore, revival from git reset --hard HEAD^
find the log, and reset the "reset"
git reflog -n 3
git reset --hard "HEAD@{1}"
๐ Repository Management
Clone and rename the directory
# git clone url [directory-name]
git clone git@github.com:n350071/rails-on-k8s.git rails-on-k8s-refactor
๐ Setting
GitHub
Remote repository
# check the remote repository
git remote -v
# add (git remote add [name] [url])
git remote add origin git@github.com:n350071/rails-starter-kit-with-docker.git
# Change remote name from 'origin' to 'destination'
$ git remote rename origin destination
# change the default remote repository for 'push'
git push -u <remote_name> <local_branch_name>
.gitconfig
$ cat .gitconfig
[alias]
check = !git checkout $(git branch | sed 's/*//g' | sed 's/ //g' | peco)
bcp = !git branch | peco | sed 's/*//g' | sed 's/ //g' | tr -d '\n' | pbcopy
[log]
date = iso-local
[core]
quotepath = false
[commit]
template = /Users/naoki/.git_commit_template
.git_commit_template
$ cat .git_commit_template
# === format ===
# :emoji: issue-id issue-title
# ==== example ====
# :+1: SR-400 ่ช่จผๆฉ่ฝใฎๅฎ่ฃ
# :bug: BG-128 Thanksใกใใปใผใธใฏ๏ผ้ใงใฏใชใ๏ผ้
# ==== Emojis ====
# ๐ ๅฐใใชๆฉ่ฝ่ฟฝๅ :+1:
# ๐ ๅคงใใชๆฉ่ฝ่ฟฝๅ :tada:
# ๐ ใใฐไฟฎๆญฃ :bug:
# ๐ ใชใใกใฏใฟใชใณใฐ :green_heart:
# โ
ใในใใฎ่ฟฝๅ :white_check_mark:
# ๐ ใใญใฅใกใณใ่ฟฝๅ :memo:
# ๐ ใใใฉใผใใณในๆนๅ :rocket:
# ๐ ใใผใธใงใณใขใใ :up:
# ๐
ๅใใใใซใใ :sweat_smile:
# โ๏ธ ไธๆธใ :no_entry:
# โ๏ธ ่จไบๆ็จฟ :pencil:
Top comments (0)