Git Rebase vs Merge, GIt Reset vs Revert

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 -a
 Committer: 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 --edit

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 1 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 -b
 Committer: 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 --edit

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 1 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 +0800

    master -b

commit 1d61d993fb06569f5021bd9d1fda61de2440a94d
Author: Yongzhi Liu <yongzhiliu@Yongzhis-MacBook-Pro.local>
Date:   Thu Apr 9 07:28:36 2020 +0800

    master -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 f
 Committer: 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 --edit

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 1 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 e
 Committer: 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 --edit

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 1 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 is
	commit
yongzhiliu@Yongzhis-MacBook-Pro testGit % git commit -m 'master c' 
[master 7920ddb] master c
 Committer: 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 --edit

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 1 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 branch
  f
* 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 directory
   init      Create an empty Git repository or reinitialize an existing one

work on the current change (see also: git help everyday)
   add       Add file contents to the index
   mv        Move or rename a file, a directory, or a symlink
   restore   Restore working tree files
   rm        Remove files from the working tree and from the index

examine the history and state (see also: git help revisions)
   bisect    Use binary search to find the commit that introduced a bug
   diff      Show changes between commits, commit and working tree, etc
   grep      Print lines matching a pattern
   log       Show commit logs
   show      Show various types of objects
   status    Show the working tree status

grow, mark and tweak your common history
   branch    List, create, or delete branches
   commit    Record changes to the repository
   merge     Join two or more development histories together
   rebase    Reapply commits on top of another base tip
   reset     Reset current HEAD to the specified state
   switch    Switch branches
   tag       Create, list, delete or verify a tag object signed with GPG

collaborate (see also: git help workflows)
   fetch     Download objects and refs from another repository
   pull      Fetch from and integrate with another repository or a local branch
   push      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 1d61d993fb06569f5021bd9d1fda61de2440a94d
  Author: Yongzhi Liu <yongzhiliu@Yongzhis-MacBook-Pro.local>
  Date:   Thu Apr 9 07:28:36 2020 +0800
  
      master -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 a
 Committer: 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 --edit

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 1 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 b
 Committer: 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 --edit

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 1 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 -f
 Committer: 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 --edit

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 1 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 f
 Committer: 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 --edit

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 1 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 c
 Committer: 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 --edit

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 1 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-forward
 f.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 hello
 Committer: 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 --edit

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 1 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 world
 Committer: 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 --edit

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 1 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 hello
 Committer: 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 --edit

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 1 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 world
 Committer: 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 --edit

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 1 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 try
	git rebase (--continue | --abort | --skip)
If that is not the case, please
	rm -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 try
	git rebase (--continue | --abort | --skip)
If that is not the case, please
	rm -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 % 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值