Skip to content

Instantly share code, notes, and snippets.

@b2977053
Created March 19, 2020 09:51
Show Gist options
  • Save b2977053/bec221eb25193cc42c9ddd147b0dbc98 to your computer and use it in GitHub Desktop.
Save b2977053/bec221eb25193cc42c9ddd147b0dbc98 to your computer and use it in GitHub Desktop.
# 建立資料夾 與 版本庫
mkdir git-rebase-demo
cd git-rebase-demo
git init
# 新增檔案 a.txt、b.txt 並分別提交。
echo 'a.txt first commit' > a.txt
git add .
git commit -m 'a.txt first commit'
echo 'b.txt first commit' > b.txt
git add .
git commit -m 'b.txt first commit'
# 新增分支 branch_1
git checkout -b branch_1
# 新增檔案 C.txt、D.txt 並分別提交。
echo 'C.txt first commit' > C.txt
git add .
git commit -m 'C.txt first commit'
echo 'D.txt first commit' > D.txt
git add .
git commit -m 'D.txt first commit'
# 回 master 繼續新增 E.txt
git checkout master
echo 'E.txt first commit' > E.txt
git add .
git commit -m 'E.txt first commit'
start .
#
# 改名
# reword
#
git rebase 'HEAD^1' -i
#
# 調換 commit 的順序
#
# 查看何時分支出來
git reflog
# rebase 分支 branch_1 ,基底不變
git checkout branch_1
git rebase <SHA-1> -i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment