Git merge vs Rebase


构造场景如下:

https://zhuanlan.zhihu.com/p/29682134?utm_source=wechat_session

Git Rest & Revert







在自己的分支上可以使用git reset, 如果是公共分支建议使用git revert,这样可以记录历史。Rest是指针的移动,revert是把回退当作一次新的提交

Rebase Merge 练习
yongzhiliu@Yongzhis-MacBook-Pro ~ % cd /Users/yongzhiliu/Desktop/NHO
yongzhiliu@Yongzhis-MacBook-Pro NHO % mkdir testGit
yongzhiliu@Yongzhis-MacBook-Pro NHO % ls
Screen Shot 2020-03-31 at 3.22.27 PM.png   Screen Shot 2020-03-31 at 3.59.35 PM.png   Screen Shot 2020-03-31 at 4.44.38 PM.png   testGit
Screen Shot 2020-03-31 at 3.39.19 PM.png   Screen Shot 2020-03-31 at 4.32.48 PM.png   Screen Shot 2020-03-31 at 4.54.39 PM.png
yongzhiliu@Yongzhis-MacBook-Pro NHO % cd testDir
cd: no such file or directory: testDir
yongzhiliu@Yongzhis-MacBook-Pro NHO % cd testGit
yongzhiliu@Yongzhis-MacBook-Pro testGit % ls
yongzhiliu@Yongzhis-MacBook-Pro testGit % git init
Initialized empty Git repository in /Users/yongzhiliu/Desktop/NHO/testGit/.git/
yongzhiliu@Yongzhis-MacBook-Pro testGit % vi index.txt
yongzhiliu@Yongzhis-MacBook-Pro testGit % ls
index.txt
yongzhiliu@Yongzhis-MacBook-Pro testGit % less index.txt
yongzhiliu@Yongzhis-MacBook-Pro testGit % git add .
yongzhiliu@Yongzhis-MacBook-Pro testGit % git log
fatal: your current branch 'master' does not have any commits yet
yongzhiliu@Yongzhis-MacBook-Pro testGit % gs
zsh: command not found: gs
yongzhiliu@Yongzhis-MacBook-Pro testGit % git commit -m "master -a"
[master (root-commit) 1d61d99] master -aCommitter: Yongzhi Liu <yongzhiliu@Yongzhis-MacBook-Pro.local>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly. Run the
following command and follow the instructions in your editor to edit
your configuration file:git config --global --editAfter doing this, you may fix the identity used for this commit with:git commit --amend --reset-author1 file changed, 1 insertion(+)create mode 100644 index.txt
yongzhiliu@Yongzhis-MacBook-Pro testGit % git log --oneline
1d61d99 (HEAD -> master) master -a
yongzhiliu@Yongzhis-MacBook-Pro testGit % vi index.txt
yongzhiliu@Yongzhis-MacBook-Pro testGit % git add .
yongzhiliu@Yongzhis-MacBook-Pro testGit % git commit -m "master -b"
[master b81e0a5] master -bCommitter: Yongzhi Liu <yongzhiliu@Yongzhis-MacBook-Pro.local>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly. Run the
following command and follow the instructions in your editor to edit
your configuration file:git config --global --editAfter doing this, you may fix the identity used for this commit with:git commit --amend --reset-author1 file changed, 1 insertion(+)
yongzhiliu@Yongzhis-MacBook-Pro testGit % git log --oneline
b81e0a5 (HEAD -> master) master -b
1d61d99 master -a
yongzhiliu@Yongzhis-MacBook-Pro testGit % git checkout -f
yongzhiliu@Yongzhis-MacBook-Pro testGit % git log
commit b81e0a5c466dd3a6e45308e6e509e396753e1798 (HEAD -> master)
Author: Yongzhi Liu <yongzhiliu@Yongzhis-MacBook-Pro.local>
Date:   Thu Apr 9 07:29:58 2020 +0800master -bcommit 1d61d993fb06569f5021bd9d1fda61de2440a94d
Author: Yongzhi Liu <yongzhiliu@Yongzhis-MacBook-Pro.local>
Date:   Thu Apr 9 07:28:36 2020 +0800master -a
yongzhiliu@Yongzhis-MacBook-Pro testGit % git checkout -b f
Switched to a new branch 'f'
yongzhiliu@Yongzhis-MacBook-Pro testGit % vi f.txt
yongzhiliu@Yongzhis-MacBook-Pro testGit % ls
f.txt        index.txt
yongzhiliu@Yongzhis-MacBook-Pro testGit % vi f.txt
yongzhiliu@Yongzhis-MacBook-Pro testGit % vi f.txt
yongzhiliu@Yongzhis-MacBook-Pro testGit % ls
f.txt        index.txt
yongzhiliu@Yongzhis-MacBook-Pro testGit % git add .
yongzhiliu@Yongzhis-MacBook-Pro testGit % git commit -m 'Branch f'
[f af352fa] Branch fCommitter: Yongzhi Liu <yongzhiliu@Yongzhis-MacBook-Pro.local>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly. Run the
following command and follow the instructions in your editor to edit
your configuration file:git config --global --editAfter doing this, you may fix the identity used for this commit with:git commit --amend --reset-author1 file changed, 1 insertion(+)create mode 100644 f.txt
yongzhiliu@Yongzhis-MacBook-Pro testGit % git log --oneline
af352fa (HEAD -> f) Branch f
b81e0a5 (master) master -b
1d61d99 master -a
yongzhiliu@Yongzhis-MacBook-Pro testGit % vi f.txt
yongzhiliu@Yongzhis-MacBook-Pro testGit % git add .
yongzhiliu@Yongzhis-MacBook-Pro testGit % git commit -m 'Branch e'
[f 82809a8] Branch eCommitter: Yongzhi Liu <yongzhiliu@Yongzhis-MacBook-Pro.local>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly. Run the
following command and follow the instructions in your editor to edit
your configuration file:git config --global --editAfter doing this, you may fix the identity used for this commit with:git commit --amend --reset-author1 file changed, 1 insertion(+)
yongzhiliu@Yongzhis-MacBook-Pro testGit % git log --oneline
82809a8 (HEAD -> f) Branch e
af352fa Branch f
b81e0a5 (master) master -b
1d61d99 master -a
yongzhiliu@Yongzhis-MacBook-Pro testGit % git checkout master
Switched to branch 'master'
yongzhiliu@Yongzhis-MacBook-Pro testGit % vi index.txt
yongzhiliu@Yongzhis-MacBook-Pro testGit % git add .
yongzhiliu@Yongzhis-MacBook-Pro testGit % git commmit -m 'master c'
git: 'commmit' is not a git command. See 'git --help'.The most similar command iscommit
yongzhiliu@Yongzhis-MacBook-Pro testGit % git commit -m 'master c'
[master 7920ddb] master cCommitter: Yongzhi Liu <yongzhiliu@Yongzhis-MacBook-Pro.local>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly. Run the
following command and follow the instructions in your editor to edit
your configuration file:git config --global --editAfter doing this, you may fix the identity used for this commit with:git commit --amend --reset-author1 file changed, 1 insertion(+)
yongzhiliu@Yongzhis-MacBook-Pro testGit % git log --oneline
7920ddb (HEAD -> master) master c
b81e0a5 master -b
1d61d99 master -a
yongzhiliu@Yongzhis-MacBook-Pro testGit % gb
zsh: command not found: gb
yongzhiliu@Yongzhis-MacBook-Pro testGit % git branchf
* master
yongzhiliu@Yongzhis-MacBook-Pro testGit % git merge f
Merge made by the 'recursive' strategy.f.txt | 2 ++1 file changed, 2 insertions(+)create mode 100644 f.txt
yongzhiliu@Yongzhis-MacBook-Pro testGit % git log --oneline
3f8f40d (HEAD -> master) Merge branch 'f'
7920ddb master c
82809a8 (f) Branch e
af352fa Branch f
b81e0a5 master -b
1d61d99 master -a
yongzhiliu@Yongzhis-MacBook-Pro testGit % git view
git: 'view' is not a git command. See 'git --help'.
yongzhiliu@Yongzhis-MacBook-Pro testGit % git --graph
unknown option: --graph
usage: git [--version] [--help] [-C <path>] [-c <name>=<value>][--exec-path[=<path>]] [--html-path] [--man-path] [--info-path][-p | --paginate | -P | --no-pager] [--no-replace-objects] [--bare][--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]<command> [<args>]
yongzhiliu@Yongzhis-MacBook-Pro testGit % git -graph
unknown option: -graph
usage: git [--version] [--help] [-C <path>] [-c <name>=<value>][--exec-path[=<path>]] [--html-path] [--man-path] [--info-path][-p | --paginate | -P | --no-pager] [--no-replace-objects] [--bare][--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]<command> [<args>]
yongzhiliu@Yongzhis-MacBook-Pro testGit % git --help
usage: git [--version] [--help] [-C <path>] [-c <name>=<value>][--exec-path[=<path>]] [--html-path] [--man-path] [--info-path][-p | --paginate | -P | --no-pager] [--no-replace-objects] [--bare][--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]<command> [<args>]These are common Git commands used in various situations:start a working area (see also: git help tutorial)clone     Clone a repository into a new directoryinit      Create an empty Git repository or reinitialize an existing onework on the current change (see also: git help everyday)add       Add file contents to the indexmv        Move or rename a file, a directory, or a symlinkrestore   Restore working tree filesrm        Remove files from the working tree and from the indexexamine the history and state (see also: git help revisions)bisect    Use binary search to find the commit that introduced a bugdiff      Show changes between commits, commit and working tree, etcgrep      Print lines matching a patternlog       Show commit logsshow      Show various types of objectsstatus    Show the working tree statusgrow, mark and tweak your common historybranch    List, create, or delete branchescommit    Record changes to the repositorymerge     Join two or more development histories togetherrebase    Reapply commits on top of another base tipreset     Reset current HEAD to the specified stateswitch    Switch branchestag       Create, list, delete or verify a tag object signed with GPGcollaborate (see also: git help workflows)fetch     Download objects and refs from another repositorypull      Fetch from and integrate with another repository or a local branchpush      Update remote refs along with associated objects'git help -a' and 'git help -g' list available subcommands and some
concept guides. See 'git help <command>' or 'git help <concept>'
to read about a specific subcommand or concept.
See 'git help git' for an overview of the system.
yongzhiliu@Yongzhis-MacBook-Pro testGit % git testgit --graph
git: 'testgit' is not a git command. See 'git --help'.
yongzhiliu@Yongzhis-MacBook-Pro testGit % testgit --graph
zsh: command not found: testgit
yongzhiliu@Yongzhis-MacBook-Pro testGit % git log -graph
fatal: unrecognized argument: -graph
yongzhiliu@Yongzhis-MacBook-Pro testGit % git log --graph
*   commit 3f8f40d941149b32fbd7fc9c8473eba1d2c8a831 (HEAD -> master)
|\  Merge: 7920ddb 82809a8
| | Author: Yongzhi Liu <yongzhiliu@Yongzhis-MacBook-Pro.local>
| | Date:   Thu Apr 9 07:38:32 2020 +0800
| |
| |     Merge branch 'f'
| |
| * commit 82809a80dcc90728a917542593ddb92c16a9da06 (f)
| | Author: Yongzhi Liu <yongzhiliu@Yongzhis-MacBook-Pro.local>
| | Date:   Thu Apr 9 07:36:09 2020 +0800
| |
| |     Branch e
| |
| * commit af352fad3ca55431b82b7e07d59c67e365bc9d45
| | Author: Yongzhi Liu <yongzhiliu@Yongzhis-MacBook-Pro.local>
| | Date:   Thu Apr 9 07:35:13 2020 +0800
| |
| |     Branch f
| |
* | commit 7920ddbd277c6f1506ac57fc97423877fcd81148
|/  Author: Yongzhi Liu <yongzhiliu@Yongzhis-MacBook-Pro.local>
|   Date:   Thu Apr 9 07:37:41 2020 +0800
|
|       master c
|
* commit b81e0a5c466dd3a6e45308e6e509e396753e1798
| Author: Yongzhi Liu <yongzhiliu@Yongzhis-MacBook-Pro.local>
| Date:   Thu Apr 9 07:29:58 2020 +0800
|
|     master -b
|
* commit 1d61d993fb06569f5021bd9d1fda61de2440a94dAuthor: Yongzhi Liu <yongzhiliu@Yongzhis-MacBook-Pro.local>Date:   Thu Apr 9 07:28:36 2020 +0800master -a
yongzhiliu@Yongzhis-MacBook-Pro testGit % git log --graph --oneline
*   3f8f40d (HEAD -> master) Merge branch 'f'
|\
| * 82809a8 (f) Branch e
| * af352fa Branch f
* | 7920ddb master c
|/
* b81e0a5 master -b
* 1d61d99 master -a
yongzhiliu@Yongzhis-MacBook-Pro testGit % cd ..
yongzhiliu@Yongzhis-MacBook-Pro NHO % mkdir testGitRebase
yongzhiliu@Yongzhis-MacBook-Pro NHO % git init
Initialized empty Git repository in /Users/yongzhiliu/Desktop/NHO/.git/
yongzhiliu@Yongzhis-MacBook-Pro NHO % vi index.txt
yongzhiliu@Yongzhis-MacBook-Pro NHO % git add .
warning: adding embedded git repository: testGit
hint: You've added another git repository inside your current repository.
hint: Clones of the outer repository will not contain the contents of
hint: the embedded repository and will not know how to obtain it.
hint: If you meant to add a submodule, use:
hint:
hint:   git submodule add <url> testGit
hint:
hint: If you added this path by mistake, you can remove it from the
hint: index with:
hint:
hint:   git rm --cached testGit
hint:
hint: See "git help submodule" for more information.
yongzhiliu@Yongzhis-MacBook-Pro NHO % rm .git
rm: .git: is a directory
yongzhiliu@Yongzhis-MacBook-Pro NHO % rm -rf .git/
yongzhiliu@Yongzhis-MacBook-Pro NHO % ls
Screen Shot 2020-03-31 at 3.22.27 PM.png    Screen Shot 2020-03-31 at 4.32.48 PM.png    index.txt
Screen Shot 2020-03-31 at 3.39.19 PM.png    Screen Shot 2020-03-31 at 4.44.38 PM.png    testGit
Screen Shot 2020-03-31 at 3.59.35 PM.png    Screen Shot 2020-03-31 at 4.54.39 PM.png    testGitRebase
yongzhiliu@Yongzhis-MacBook-Pro NHO % cd testGit
yongzhiliu@Yongzhis-MacBook-Pro testGit % ls
f.txt       index.txt
yongzhiliu@Yongzhis-MacBook-Pro testGit % git log --oneline
3f8f40d (HEAD -> master) Merge branch 'f'
7920ddb master c
82809a8 (f) Branch e
af352fa Branch f
b81e0a5 master -b
1d61d99 master -a
yongzhiliu@Yongzhis-MacBook-Pro testGit % cd ..
yongzhiliu@Yongzhis-MacBook-Pro NHO % cd testGitRebase
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % git init
Initialized empty Git repository in /Users/yongzhiliu/Desktop/NHO/testGitRebase/.git/
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % vi index.txt
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % ls
index.txt
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % vi index.txt
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % vi index.txt
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % git add .
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % git commit "master a"
error: pathspec 'master a' did not match any file(s) known to git
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % git commit -m "master a"
[master (root-commit) a42a277] master aCommitter: Yongzhi Liu <yongzhiliu@Yongzhis-MacBook-Pro.local>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly. Run the
following command and follow the instructions in your editor to edit
your configuration file:git config --global --editAfter doing this, you may fix the identity used for this commit with:git commit --amend --reset-author1 file changed, 1 insertion(+)create mode 100644 index.txt
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % git log --oneline
a42a277 (HEAD -> master) master a
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % vi index.txt
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % git add .
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % git commit -m 'master b'
[master ce0d522] master bCommitter: Yongzhi Liu <yongzhiliu@Yongzhis-MacBook-Pro.local>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly. Run the
following command and follow the instructions in your editor to edit
your configuration file:git config --global --editAfter doing this, you may fix the identity used for this commit with:git commit --amend --reset-author1 file changed, 1 insertion(+)
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % git log --oneline
ce0d522 (HEAD -> master) master b
a42a277 master a
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % git checkout f
error: pathspec 'f' did not match any file(s) known to git
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % git checkout -b f
Switched to a new branch 'f'
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % vi f.txt
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % vi f.txt
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % git add .
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % git commit 'branch -f'
error: pathspec 'branch -f' did not match any file(s) known to git
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % git commit -m 'branch -f'
[f 2d75d01] branch -fCommitter: Yongzhi Liu <yongzhiliu@Yongzhis-MacBook-Pro.local>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly. Run the
following command and follow the instructions in your editor to edit
your configuration file:git config --global --editAfter doing this, you may fix the identity used for this commit with:git commit --amend --reset-author1 file changed, 1 insertion(+)create mode 100644 f.txt
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % git log --oneline
2d75d01 (HEAD -> f) branch -f
ce0d522 (master) master b
a42a277 master a
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % vi f.txt
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % git add .
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % git commit -m "branch f"
[f 56e5ce1] branch fCommitter: Yongzhi Liu <yongzhiliu@Yongzhis-MacBook-Pro.local>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly. Run the
following command and follow the instructions in your editor to edit
your configuration file:git config --global --editAfter doing this, you may fix the identity used for this commit with:git commit --amend --reset-author1 file changed, 1 insertion(+)
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % git log --oneline
56e5ce1 (HEAD -> f) branch f
2d75d01 branch -f
ce0d522 (master) master b
a42a277 master a
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % git checkout master
Switched to branch 'master'
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % vi index.txt
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % git checkout f
M   index.txt
Switched to branch 'f'
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % git checkout -b f
fatal: A branch named 'f' already exists.
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % git checkout f
M   index.txt
Already on 'f'
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % git log --oneline
56e5ce1 (HEAD -> f) branch f
2d75d01 branch -f
ce0d522 (master) master b
a42a277 master a
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % git checkout master
'M   index.txt
Switched to branch 'master'
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % git log --oneline
ce0d522 (HEAD -> master) master b
a42a277 master a
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % git add ..
fatal: ..: '..' is outside repository
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % git add .
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % git commit -m 'master c'
[master 31fefca] master cCommitter: Yongzhi Liu <yongzhiliu@Yongzhis-MacBook-Pro.local>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly. Run the
following command and follow the instructions in your editor to edit
your configuration file:git config --global --editAfter doing this, you may fix the identity used for this commit with:git commit --amend --reset-author1 file changed, 1 insertion(+)
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % git log --oneline
31fefca (HEAD -> master) master c
ce0d522 master b
a42a277 master a
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % git checkout f
Switched to branch 'f'
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % git rebase master
First, rewinding head to replay your work on top of it...
Applying: branch -f
Applying: branch f
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % git log --oneline
d05c693 (HEAD -> f) branch f
7c4e520 branch -f
31fefca (master) master c
ce0d522 master b
a42a277 master a
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % git log --graph --oneline
* d05c693 (HEAD -> f) branch f
* 7c4e520 branch -f
* 31fefca (master) master c
* ce0d522 master b
* a42a277 master a
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % git checkout master
Switched to branch 'master'
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % git log --graph --oneline
* 31fefca (HEAD -> master) master c
* ce0d522 master b
* a42a277 master a
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % git merge f
Updating 31fefca..d05c693
Fast-forwardf.txt | 2 ++1 file changed, 2 insertions(+)create mode 100644 f.txt
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % git log --graph --oneline
* d05c693 (HEAD -> master, f) branch f
* 7c4e520 branch -f
* 31fefca master c
* ce0d522 master b
* a42a277 master a
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % vi index.txt
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % git add .
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % git commit -m 'master hello'
[master a1d534a] master helloCommitter: Yongzhi Liu <yongzhiliu@Yongzhis-MacBook-Pro.local>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly. Run the
following command and follow the instructions in your editor to edit
your configuration file:git config --global --editAfter doing this, you may fix the identity used for this commit with:git commit --amend --reset-author1 file changed, 2 insertions(+)
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % vi index.txt
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % git add .
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % git commit -m 'master world'
[master d29fd00] master worldCommitter: Yongzhi Liu <yongzhiliu@Yongzhis-MacBook-Pro.local>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly. Run the
following command and follow the instructions in your editor to edit
your configuration file:git config --global --editAfter doing this, you may fix the identity used for this commit with:git commit --amend --reset-author1 file changed, 1 insertion(+)
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % git log --oneline --graph
* d29fd00 (HEAD -> master) master world
* a1d534a master hello
* d05c693 (f) branch f
* 7c4e520 branch -f
* 31fefca master c
* ce0d522 master b
* a42a277 master a
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % git rebase -i HEAD~~
error: cannot 'fixup' without a previous commit
You can fix this with 'git rebase --edit-todo' and then run 'git rebase --continue'.
Or you can abort the rebase with 'git rebase --abort'.
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % git log --oneline --graph
* d05c693 (HEAD, f) branch f
* 7c4e520 branch -f
* 31fefca master c
* ce0d522 master b
* a42a277 master a
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % less index.txt
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % vi index.txt
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % vi index.txt
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % git add .
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % git commit -m 'master hello'
[detached HEAD 61b5da9] master helloCommitter: Yongzhi Liu <yongzhiliu@Yongzhis-MacBook-Pro.local>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly. Run the
following command and follow the instructions in your editor to edit
your configuration file:git config --global --editAfter doing this, you may fix the identity used for this commit with:git commit --amend --reset-author1 file changed, 2 insertions(+)
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % vi index.txt
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % git add .
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % git commit -m 'master world'
[detached HEAD 0b8b2ab] master worldCommitter: Yongzhi Liu <yongzhiliu@Yongzhis-MacBook-Pro.local>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly. Run the
following command and follow the instructions in your editor to edit
your configuration file:git config --global --editAfter doing this, you may fix the identity used for this commit with:git commit --amend --reset-author1 file changed, 1 insertion(+)
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % git log --oneline --graph
* 0b8b2ab (HEAD) master world
* 61b5da9 master hello
* d05c693 (f) branch f
* 7c4e520 branch -f
* 31fefca master c
* ce0d522 master b
* a42a277 master a
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % git rebase -i HEAD~~
fatal: It seems that there is already a rebase-merge directory, and
I wonder if you are in the middle of another rebase.  If that is the
case, please trygit rebase (--continue | --abort | --skip)
If that is not the case, pleaserm -fr ".git/rebase-merge"
and run me again.  I am stopping in case you still have something
valuable there.yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % rm -fr ".git/rebase-merge
dquote>
dquote>
dquote> "
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % git log --oneline --graph
* 0b8b2ab (HEAD) master world
* 61b5da9 master hello
* d05c693 (f) branch f
* 7c4e520 branch -f
* 31fefca master c
* ce0d522 master b
* a42a277 master a
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % git rebase -i HEAD~~
fatal: It seems that there is already a rebase-merge directory, and
I wonder if you are in the middle of another rebase.  If that is the
case, please trygit rebase (--continue | --abort | --skip)
If that is not the case, pleaserm -fr ".git/rebase-merge"
and run me again.  I am stopping in case you still have something
valuable there.yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % rm -fr ".git/rebase-merge"
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % rm -fr ".git/rebase-merge"
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % git rebase -i HEAD~~
Successfully rebased and updated detached HEAD.
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % git log --oneline --graph
* 35c96ae (HEAD) master hello
* d05c693 (f) branch f
* 7c4e520 branch -f
* 31fefca master c
* ce0d522 master b
* a42a277 master a
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % less index.txt
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase % git reflog
35c96ae (HEAD) HEAD@{0}: rebase -i (fixup): master hello
61b5da9 HEAD@{1}: rebase -i (start): checkout HEAD~~
0b8b2ab HEAD@{2}: commit: master world
61b5da9 HEAD@{3}: commit: master hello
d05c693 (f) HEAD@{4}: rebase -i (start): checkout HEAD~~
d29fd00 (master) HEAD@{5}: commit: master world
a1d534a HEAD@{6}: commit: master hello
d05c693 (f) HEAD@{7}: merge f: Fast-forward
31fefca HEAD@{8}: checkout: moving from f to master
d05c693 (f) HEAD@{9}: rebase finished: returning to refs/heads/f
d05c693 (f) HEAD@{10}: rebase: branch f
7c4e520 HEAD@{11}: rebase: branch -f
31fefca HEAD@{12}: rebase: checkout master
56e5ce1 HEAD@{13}: checkout: moving from master to f
31fefca HEAD@{14}: commit: master c
ce0d522 HEAD@{15}: checkout: moving from f to master
56e5ce1 HEAD@{16}: checkout: moving from f to f
56e5ce1 HEAD@{17}: checkout: moving from master to f
ce0d522 HEAD@{18}: checkout: moving from f to master
56e5ce1 HEAD@{19}: commit: branch f
2d75d01 HEAD@{20}: commit: branch -f
ce0d522 HEAD@{21}: checkout: moving from master to f
ce0d522 HEAD@{22}: commit: master b
a42a277 HEAD@{23}: commit (initial): master a
yongzhiliu@Yongzhis-MacBook-Pro testGitRebase %

Git Rebase vs Merge, GIt Reset vs Revert相关推荐

  1. 你什么时候使用git rebase而不是git merge?

    什么时候建议使用git rebase与git merge ? 成功改造后我还需要合并吗? #1楼 在合并/ rebase之前: A <- B <- C [master] ^\D <- ...

  2. Git 回滚 checkout、reset、revert

    Git 回滚 checkout.reset.revert 首先看一下 Git 的工作流程 checkout 是检出的意思,作用是将某次 commit 的状态检出到工作区,它的过程是先将 HEAD 指向 ...

  3. Git rebase 和 merge讲解

    git合并代码方式主要有两种方式,分别为: 1.merge处理,这是大家比较能理解的方式. 2.rebase处理,中文此处翻译为衍合过程. 先来两张合理使用rebase,merge和只使用merge的 ...

  4. 使用git rebase和merge合并特定commits到master分支

    可能大家知道如何使用cherry-pick从一个分支合并特定的commits到另一个分支,但是这个方法不能保留原始的提交信息(比如提交时间线等),而如果要保留合并过来的commits的所有提交信息,那 ...

  5. 你在开发过程中使用Git Rebase还是Git Merge?

    1. 痛苦吗?代码历史中的迷失羔羊 我们先来看一个真实的代码提交历史图形化截图: 图片源自 https://storage.kraken.io/kk8yWPxzXVfBD3654oMN/c8b97f4 ...

  6. 从git commit号码 revert_git revert amp; git rebase amp; commit 分支图

    今天学了几个git技巧,分享下: 问题一:上线后的代码出现问题,如何回滚代码? 代码合入master之后,上线发现有问题,其他同事也等待上线,怎么办? 使用git revert .参考 How to ...

  7. git rebase VS git merge? 更优雅的 git 合并方式值得拥有

    写在前面 如果你不能很好的应用 Git,那么这里为你提供一个非常棒的 Git 在线练习工具 Git Online ,你可以更直观的看到你所使用的命令会产生什么效果 另外,你在使用 Git 合并分支时只 ...

  8. git merge 和 git rebase详解

    git merge 和 git rebase 都是用来合并两个分支的. git merge b   #把b分支合并到当前分支 git rebase b   #把b分支合并到当前分支 --------- ...

  9. git(8)---git merge 和 git rebase 小结

    git merge 和 git rebase 小结 git merge是用来合并两个分支的. git merge b # 将b分支合并到当前分支 同样 git rebase b,也是把 b分支合并到当 ...

最新文章

  1. 计算机信息管理技术 互联网,计算机信息管理技术在网络安全中的运用思路
  2. java中的日期时间的计算与比较
  3. 在Windows Media Center中收听超过100,000个广播电台
  4. 如何使用Hibernate批处理INSERT和UPDATE语句
  5. Xcode的Architectures和Valid Architectures的区别
  6. 纠删码存储系统中的投机性部分写技术
  7. php执行跟踪_PHP 代码调试跟踪工具 Ytrace
  8. request.getRequestURL()和request.getRequestURI()区别
  9. android的子菜单是否支持嵌套,Android的两种菜单
  10. Atitit React的相关概念东东 attilax总结 v3
  11. 毕设题目:Matlab语音识别
  12. matlab时域频域信号特征提取资料整合
  13. 通达OA任意用户登录漏洞手工复现
  14. 【隧道篇 / IPsec】(5.6) ❀ 01. IPsec 结构与需求 ❀ FortiGate 防火墙
  15. FFMPEG学习【libavcodec】:编解码器:硬件加速器桥:VDA
  16. 笨鸟的平凡之路-KETTLE的安装
  17. Join the IT | 一个初生程序猿的内心独白
  18. 349-git各阶段版本回退命令
  19. 《中国历代政治得失》读书笔记
  20. Win7 提示“请考虑更换电池”

热门文章

  1. 大学英语综合教程一 Unit 6 课文内容英译中 中英翻译
  2. Aspose.word组件介绍
  3. php 模拟数猴子数大王,猴子大王的问题
  4. Java web学习日志第一天
  5. android电视如何打开adb调试模式,分享解密某Android电视adb后门方法
  6. 【PBL项目实战】户外智慧农场项目实战系列之4——Mind+Mixly双平台ESP32数据上云及云端可视化实时展示
  7. Python全栈笔记(练习题,持续更新)
  8. pyspider 爬取bing壁纸
  9. STAC: A Simple Semi-Supervised Learning Framework for Object Detection
  10. 【教程】枫叶文字效果!