Skip to content

Commit f0f1458

Browse files
committed
main
1 parent 2ffad4a commit f0f1458

File tree

11 files changed

+148
-33
lines changed

11 files changed

+148
-33
lines changed

docs/document/Skill/Git/docs/1.Overview.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,17 @@
1111
- you can rollback to one snapshot by `reset`.
1212
3. **Branching**: a special form of commit that can represent a divergence of the commit graph.
1313
- each branch is essentially a **dynamic head commit** of that divergence, it can traverse back to its start point to delineated the branch.
14-
- a branch can merge to another on `pull` or `merge`
15-
4. **Synchronization**: working with remotes and locals
14+
- branching is all about how to attach/detach a commit
15+
4. **History & Reset**
16+
- inspect local history `reflog` and commit history `log`
17+
- each history is just a commit, tracked or wild, attached or detached
18+
- use `bisect` to binary search the commit introduced *bad* things.
19+
- revert changes of a commit by `git revert`(with *revert commit*)
20+
- reset to commit with altered history
21+
5. **Synchronization**: working with remotes and locals
22+
- download remote branches by `fetch`
23+
- `merge` or `rebase` remote branches
24+
- use `pull` as shortcut of `fetch` plus `merge/rebase`
1625

1726
## Getting Help
1827

docs/document/Skill/Git/docs/2.Commit.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,11 @@ Three special symbols for traversing back in git:
5757
5858
> [!NOTE]
5959
> When saying `HEAD` we're referring to the head of worktree which might walk across different branches as you checkout.
60-
> When a branch name is explicitly specified or elided(representing the current branch), the **reflog** can differ from `HEAD` since it only contains things about the branch.
61-
> That is, such commit expression with `@` can point to different commit as you specify/elide the identifier or not.
60+
> When a branch name is explicitly specified or elided(representing the current branch), the **reflog** can differ from `HEAD`'s since it's branch specific
6261
6362
### Identifier Expansion
6463

65-
You can expand the any identifier to full commit hash using `git rev-parse <identifier>`
64+
You can expand any commit identifier to full commit hash using `git rev-parse <identifier>`
6665

6766
```console
6867
$ git rev-parse @~1

docs/document/Skill/Git/docs/3.Branching.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ So a branch besides the main branch is essentially a sequence of commits startin
1111

1212
1. **branch name**: generally refers to local branch
1313
2. `<remote>/<branch>`: refers to remote branch **copy fetched** in local
14-
3. `@{upstream}` or `@{u}`: see [Synchronization](./5.Synchronization.md#remote-branch-identifier)
14+
3. `@{upstream}` or `@{u}`: see [Remote Branch Identifier](5.Synchronization.md#remote-branch-identifier)
1515

1616
> [!NOTE]
1717
> Given the context that *upstream* is of a branch, `git rev-parse @{u}` should return the fetched latest commit hash of remote **in local**.
@@ -34,10 +34,13 @@ The fact is, commits are chained with their parent and child, so git can track b
3434
> See `git help branch` and `tldr git-branch`.
3535
> Or `git help switch` and `tldr git-switch`.
3636
37-
- `git branch`
38-
- `-d|--delete`: delete branch
39-
- `-m|--move`: rename branch
40-
- `-c|--copy`: copy branch
37+
- `-d|--delete`: delete branch
38+
- `-m|--move`: rename branch
39+
- `-c|--copy`: copy branch
40+
- `...`
41+
42+
> [!IMPORTANT]
43+
> Manipulating branches doesn't mean the commits of branches would be manipulated or deleted, they're mostly attached/detached or we can say, they live in the wild waiting to be tracked by a branch.
4144
4245
## Merging & Rebasing
4346

@@ -57,6 +60,7 @@ The fact is, commits are chained with their parent and child, so git can track b
5760
### Merge
5861

5962
A merging involves two branches, the subject of the operation is the branch to merge to.
63+
A merge operation creates a *merge commit* on the subject branch.
6064

6165
1. checkout to the branch to merge to.
6266
2. `git merge <another_branch>`

docs/document/Skill/Git/docs/4.Git History & Reset.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
- `-<n>`: limits count of commit logs
1515
- `--skip=<n>`: skip count
16+
- `--grep=<pattern>`: return commits that match the pattern
1617
- ..., see: `git help log` in *Commit Limiting* section
1718

1819
### History Exclusion
@@ -29,3 +30,87 @@ $ git log master..pwsh_es
2930
* e8284ebb96d8 (origin/pwsh_es, pwsh_es) maintainers: add sharpchen
3031
* c0c964d8ae68 powershell-editor-services: init at 4.1.0
3132
```
33+
34+
## Reflog
35+
36+
## Bisect
37+
38+
`git bisect` is a subcommand to search a target commit by testing *good* or *bad*, which delineated a range of the possible target commit, and you keep half-cut the range by testing *good* or *bad* until you met both *good* which means your found the target.
39+
40+
Assuming you have a error one testing introduced at some point but you can't figure out which commit introduced it, but you are dare to stride back to a commit that does not error which can be a start point of *good*.
41+
Correspondingly, the current commit you're on can be the start point of *bad*, that is, the error was introduced between *good* and *bad*.
42+
43+
```mermaid
44+
gitGraph
45+
commit
46+
commit
47+
commit
48+
commit id: 'good' tag: 'test passed'
49+
commit
50+
commit
51+
commit
52+
commit tag: 'might be target'
53+
commit
54+
commit
55+
commit
56+
commit id: 'bad' tag: 'test failed'
57+
```
58+
59+
1. `git bisect start`: enter *bisect* stage
60+
2. select a initial range
61+
- `git bisect bad`: select one commit that you consider *bad*, defaults to `HEAD`
62+
- `git bisect good <commit>`: select a *good* starting point, it's the commit you dare to stride back.
63+
3. git will locate you at the *middle* commit of the range, run test again
64+
- if test failed, `git bisect bad`
65+
- if succeeded, `git bisect good`
66+
- git shrinks the search range each time you mark current commit as *bad* or *good*
67+
4. keep shrinking the range until git told you the final commit clamped
68+
- the final commit returned is the commit introduced the *bad*
69+
5. `git bisect reset`: exit bisect stage
70+
71+
> [!TIP]
72+
> *good* and *bad* are not only terms can be used in `git bisect`, *old* and *new* is available when you just need to find **the first commit introduced a change**** instead of an error.
73+
> See: *Alternate terms* section in `git help bisect`
74+
75+
### Auto Bisect
76+
77+
Repeating clamping each time is a bad experience, so you'd better use `git bisect run <cmd>` to run.
78+
79+
>Note that the script (my_script in the above example) **should exit with code 0 if the current source code is good/old,
80+
>and exit with a code between 1 and 127 (inclusive), except 125, if the current source code is bad/new.**
81+
>
82+
>Any other exit code will abort the bisect process. It should be noted that a program that terminates via `exit(-1)` leaves
83+
>`$? = 255`, (see the `exit(3)` manual page), as the value is chopped with `& 0377`.
84+
85+
> [!IMPORTANT]
86+
> You should make sure the command for `git bisect run <cmd>` exits itself otherwise the operation wouldn't be automatic.
87+
> See: *Bisect run* section in `git help bisect`
88+
89+
90+
## Revert
91+
92+
Once you find a change causing an error by `git bisect` or any method you use, you might be like to *revert* **that commit of changes**.
93+
`git revert <commit>` is for trying to cancel the change of that commit, and simultaneously generate a *revert commit*.
94+
95+
When any conflict exists, you just handle it like *merge* or *rebase*, and `git revert --continue`
96+
97+
## Reset
98+
99+
- `--mixed`: the default action on reset, leaves all tracked changes since the *commit* reset to as *upstaged* state
100+
- `--soft`: leaves all tracked changes along in a *staged* state.
101+
- `--hard`: discard all tracked changes since the *commit* reset to, they're gone in the wild unless you get it back with *reflog*
102+
- see: `git help reset` for complete list of reset modes.
103+
104+
> [!NOTE]
105+
> The equivalence of `git reset --hard <commit>` is like
106+
>```console
107+
>$ git branch
108+
> main
109+
>* dev
110+
>
111+
>$ git checkout <commit> # detach from a branch
112+
>
113+
>$ git branch -D dev # stop tracking original branch(aka deleting a branch)
114+
>$ git branch -b dev # attach current commit checked out as new top of the branch(aka creating a branch)
115+
>$ echo 'reset done'
116+
>```

docs/document/Skill/Git/docs/5.Synchronization.md

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- use `git merge <remote_name>/<branch_name>` if you're ready to merge remote commits to local.
88
- `pull`: fetch remote commits for current branch and merge them into current branch.
99
- this requires the branch has a *upstream* set.
10+
- `push`: synchronize branch to remote at git host
1011

1112
## Remote
1213

@@ -27,7 +28,7 @@ $ git branch -v -r # inspect all remote branches
2728

2829
### Remote Naming Convention
2930

30-
The following convention is widely adapted by most git hosts such as github and gitlab, git host would add such remotes by convention when you fork one repository from another.
31+
The following convention is widely adopted by most git hosts such as github and gitlab, git host would add such remotes by convention when you fork one repository from another.
3132

3233
- `origin`: the remote represents the direct copy in a git host is usually named as *origin*
3334
- one repository can have one or more mirrors hosted on different git hosts, the most official one should be *origin*
@@ -45,6 +46,10 @@ The following convention is widely adapted by most git hosts such as github and
4546
- `<branch_name>@{upstream}` or `<branch_name>@{u}`: attached remote branch of `<branch_name>` **on local**.
4647
- `@{upstream}` or `@{u}`: attached remote branch of **current branch**(if you're on a branch)
4748

49+
## Fetch
50+
51+
## Merge
52+
4853
## Pull
4954

5055
`git pull <remote_name> <branch_name>`
@@ -53,3 +58,38 @@ The following convention is widely adapted by most git hosts such as github and
5358
git branch -u <remote_name>/<branch_name> [<local_branch>] # make sure you have one upstream attached to the branch
5459
git pull # pull remote commit from the attached upstream to current branch
5560
```
61+
62+
### Rebase on Pull
63+
64+
Rebasing on pull `git pull --rebase` follows such steps behind the scene:
65+
1. `git fetch <current_branch>`: fetch remote commits of current branch
66+
2. Git checkout to the remote branch and remove the new local commits, and **replay** the new local commits to on the base of remote.
67+
- oops, conflict might happen at this point.
68+
- git enters a pending stage to let you resolve the conflicts.
69+
- `git rebase --continue` to apply the resolved changes when you're ready.
70+
- or `git rebase --abort` when you like to give up the rebasing, git reattach new local commits to local branch.
71+
- this is effectively the same as moving **new local** commits to the **top** of the coming remote commits.
72+
3. Git attaches the **tail** of coming remote commits to the top of **old local** commits, rebasing finished.
73+
74+
> [!NOTE]
75+
> *replay* refers to performing all actions to generate the same new local commits on the new base.
76+
> Each stage of rebasing would be added to reflog.
77+
78+
> [!NOTE]
79+
> It's worth noting that rebasing shows a reversed side of conflicts that, `HEAD` is coming from remote while the another side is coming from local.
80+
> That's simply because the point when conflict happens, the recipient branch is the remote and the coming commits(we can't say it's a branch since it has no base at that point) are from local.
81+
>```diff
82+
><<<<<<< HEAD
83+
>Code from the remote (what you're rebasing *onto*)
84+
>=======
85+
>...Your local patch being replayed
86+
>>>>>>>> (your commit being applied)
87+
>```
88+
89+
Git generates a merge commit directly with coming commits as the default behavior, while it's recommended to use `git pull --rebase` to move your local divergence point that compared to the remote branch to the head of the coming commits.
90+
Rebasing on pull keeps the history in a intuitive order since changes from local are not pushed yet which should naturally behind the remote.
91+
92+
```gitconfig
93+
[pull]
94+
rebase = true
95+
```

docs/document/Skill/Git/docs/Collaboration/1. Synchronizing remote commits.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

docs/document/Skill/Git/docs/Collaboration/2. Pushing.md

Lines changed: 0 additions & 7 deletions
This file was deleted.

docs/document/Skill/Git/docs/Collaboration/3. Working with local branches.md

Lines changed: 0 additions & 9 deletions
This file was deleted.

docs/document/Skill/Git/docs/Collaboration/4. Credentials.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

docs/document/Skill/Git/docs/Merging/1. Fast-forward merging.md

Whitespace-only changes.

0 commit comments

Comments
 (0)