Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2ffad4a

Browse files
committed
main
1 parentbd728e9 commit2ffad4a

File tree

6 files changed

+168
-57
lines changed

6 files changed

+168
-57
lines changed
Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
11
#Overview
22

3-
-**Changes & Status**:
3+
##Concepts
4+
5+
1.**Changes & Status**:
46
- a file can be*tracked* or*untracked* which indicates whether the file is recognized by git as part of the repository.
57
- a change includes*added*,*deleted*,*modified* at the minimum unit of lines.
68
- staging meaning that you're selectively picking untracked files or changes into bucket, and waiting for**committing** them.
7-
-**Commit**: With staged changes, you're ready to generate a new snapshot, which is called*commit*.
9+
2.**Commit**: With staged changes, you're ready to generate a new snapshot, which is called*commit*.
810
- commits constructs a acyclic graph representing all revisions of your repository.
9-
- you can rollback to one snapshot by*Reset*.
10-
- a branch is derived from a commit.
11+
- you can rollback to one snapshot by`reset`.
12+
3.**Branching**: a special form of commit that can represent a divergence of the commit graph.
13+
- 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
16+
17+
##Getting Help
18+
19+
`git help <subcommand>` is the builtin command to show man page of the specified subcommand on UNIX or opening documentation html page on Windows
20+
21+
For example, open documentation for`git clone` subcommand:
22+
23+
```sh
24+
githelp clone
25+
```

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

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Git is able to compare base on two commits(usually the current and last commit),
1818
1919
##Commit Identifier
2020

21-
Each commit is identified by the uniquely generated SHA hash, you can reference the commit using the full hash or the leading 7 digit hashon git commands.
21+
Each commit is identified by the uniquely generated SHA hash, you can reference the commit using the full hash or the leading 7 digit hashfor short.
2222
Each snapshot instance of that particular commit could be found on`.git/objects/<first-2digits-of-hash>/<restof-hash>`
2323

2424
>[!NOTE]
@@ -28,6 +28,7 @@ Each snapshot instance of that particular commit could be found on `.git/objects
2828
2.**branch name**: points to**latest** commit of the branch.
2929
3.**tag name**: points to the commit of that tag.
3030
4.`HEAD` or`@`: points to the**current** commit you're at.
31+
- special identifiers like`HEAD` is independent from any branch, its a primitive and dynamic pointer for your current worktree.
3132
- for some other special identifier names, see documentation.
3233
5.`-` or`@{-1}`: previous commit you're at.
3334
-`-` is not a valid identifier in some scenarios, but you can use it in like`git checkout -` or`git merge -`.
@@ -41,7 +42,7 @@ Three special symbols for traversing back in git:
4142
1.`@`: reference backward through***reflog***, you can see such symbol like`HEAD@{1}` in`git reflog` output.
4243
-`@{-<n>}`: go to nth previously checked out commit by`git checkout`
4344
-`<commit_identifier>@{<n>}`: go to previous nth commit
44-
-`@{<n>}` is equivalent to`<current_branch>@{<n>}`, this is only valid when you're on a branch.
45+
-`@{<n>}` is equivalent to`<current_branch>@{<n>}`, this is only valid when you're on a branch(not detached).
4546
2.`~`: trace back to previous commits through**the first parent** only.
4647
-`<identifier>~3`: points to previous 3 commit from current branch.
4748
3.`^`: trace back to previous commits through a specified parent by its index.
@@ -54,14 +55,21 @@ Three special symbols for traversing back in git:
5455
>[!NOTE]
5556
>See`git help revisions` for more details
5657
57-
>[!TIP]
58-
>You can expand the commit hash by special identifier using`git rev-parse <identifier>`
59-
>```console
60-
>$ git rev-parse @~1
61-
>42804017200559f28d12757e729f95dbd18f4998
62-
>$ git rev-parse main
63-
>e7bbe687097f56d152c2291190b67d91eed4cd57
64-
>```
58+
>[!NOTE]
59+
>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.
62+
63+
###Identifier Expansion
64+
65+
You can expand the any identifier to full commit hash using`git rev-parse <identifier>`
66+
67+
```console
68+
$git rev-parse @~1
69+
42804017200559f28d12757e729f95dbd18f4998
70+
$git rev-parse main
71+
e7bbe687097f56d152c2291190b67d91eed4cd57
72+
```
6573

6674
##Commit Inspection
6775

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#Branching
2+
3+
Each branch was deviated from certain commit of another branch, and could have its own`HEAD` when actual divergence was applied.
4+
So a branch besides the main branch is essentially a sequence of commits starting with a divergence from another branch.
5+
6+
>[!IMPORTANT]
7+
>Branch is a concept upon commits, the branch is sometimes equivalent to the latest commit of that branch.
8+
>A branch is just a special commit points to latest commit of that branch and can trace back to the divergence.
9+
10+
##Branch Identifier
11+
12+
1.**branch name**: generally refers to local branch
13+
2.`<remote>/<branch>`: refers to remote branch**copy fetched** in local
14+
3.`@{upstream}` or`@{u}`: see[Synchronization](./5.Synchronization.md#remote-branch-identifier)
15+
16+
>[!NOTE]
17+
>Given the context that*upstream* is of a branch,`git rev-parse @{u}` should return the fetched latest commit hash of remote**in local**.
18+
19+
##Branch Inspection
20+
21+
A branch has its dedicated text file containing its latest commit hash at`./.git/refs/heads/<branch>`
22+
23+
```console
24+
$cat ./.git/refs/heads/msbuid_ls
25+
4bfbc0c67e39f5615e0cdc4535611af1e71040d8
26+
```
27+
28+
If the latest commit hash is the only thing the branch knows, how could it collect all of the commits when git requires to?
29+
The fact is, commits are chained with their parent and child, so git can track back along to the point where the branch was diverged.
30+
31+
##Branch Manipulation
32+
33+
>[!NOTE]
34+
>See`git help branch` and`tldr git-branch`.
35+
>Or`git help switch` and`tldr git-switch`.
36+
37+
-`git branch`
38+
-`-d|--delete`: delete branch
39+
-`-m|--move`: rename branch
40+
-`-c|--copy`: copy branch
41+
42+
##Merging & Rebasing
43+
44+
1.**General merge**: merges one branch history to another
45+
- this generates a**merge commit**, containing the information about all parents that were merged together, the merge commit is added to the branch merged into.
46+
2.**Fast forward merging**: when there' no actual divergence on graph between the parent branch and child branch, git can simply move the head pointer of current branch directly from the**merge-base** to the top commit of the branch to be merged from
47+
- generates no merge commit by default, but if do want to keep the history, use`git merge --no-ff` even when the history could be linear.
48+
3.**Rebasing**: move the**divergence point(aka the base)** to another commit.
49+
- generates no*merge commit*
50+
- alters your local commit history since its entire root of divergence has been changed.
51+
-**DO NOT** use`rebase` in public branch, use it only on your local branch.
52+
- If you're sure there's only you to work with the public branch(and its sub branches), feel free to`git push --force` to override the history on remote.
53+
54+
>[!IMPORTANT]
55+
>Always*merge* on public branches,*rebase* on local branches.
56+
57+
###Merge
58+
59+
A merging involves two branches, the subject of the operation is the branch to merge to.
60+
61+
1. checkout to the branch to merge to.
62+
2.`git merge <another_branch>`
63+
- use`--no-ff` to always generate a merge commit.
64+
65+
###Rebasing
66+
67+
Differ from`merge` subcommand,`rebase` is the change on the branch itself, only one branch is involved in the whole operation.
68+
69+
1. checkout to the branch you need to alter its merge-base
70+
2.`git rebase <commit_identifier>`

‎docs/document/Skill/Git/docs/4.Branching.md‎

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

‎docs/document/Skill/Git/docs/3.Git History & Reset.md‎renamed to ‎docs/document/Skill/Git/docs/4.Git History & Reset.md‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
#Git History & Reset
22

3-
-`git log`: commit logs thatcan be synchronized with remotes.
3+
-`git log`: commit logs thatgenerated by traversing commit graph for each time you inspect it.
44
-`git reflog`: local operation logs which is more detailed but limited to local repository.
55
-**dynamic pointers** such as`HEAD` and branches have their dedicated reflog on their own.
6+
- stores at`.git/logs/**`
7+
8+
>[!NOTE]
9+
>`git reflog` is generally faster to print than`git log` on a**large repository**, because reflog is a literal text file stored at`.git/logs/`
10+
>While`git log` has to traverse the large graph dynamically which would take a longer time to execute.
611
712
##Commit History Query
813

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#Synchronization
2+
3+
-`remote`: a git repository can have one or more remotes targeting to a uri(which means you can even add another local repository as remote with its path) exists in a git host.
4+
-`git remote add <remote_name> <uri>`.
5+
- each branch also has a*upstream* to track with remote just like the repository.
6+
-`git fetch [<remote_name>]`: fetch**all** remote commits to local but do nothing, it only fetches and store it at`refs/remotes/<remote_name>/*`
7+
- use`git merge <remote_name>/<branch_name>` if you're ready to merge remote commits to local.
8+
-`pull`: fetch remote commits for current branch and merge them into current branch.
9+
- this requires the branch has a*upstream* set.
10+
11+
##Remote
12+
13+
Remotes are implicit commits from the remote repository that can live optionally in your local repository.
14+
Each remote has its branches, which means each of its branch has a head commit stored in your local repository.
15+
16+
##Remote Inspection
17+
18+
```console
19+
$git remote -v# inspect all remotes
20+
origin git@github.com:sharpchen/nixpkgs (fetch)
21+
origin git@github.com:sharpchen/nixpkgs (push)
22+
upstream git@github.com:NixOS/nixpkgs (fetch)
23+
upstream git@github.com:NixOS/nixpkgs (push)
24+
25+
$git branch -v -r# inspect all remote branches
26+
```
27+
28+
###Remote Naming Convention
29+
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+
32+
-`origin`: the remote represents the direct copy in a git host is usually named as*origin*
33+
- one repository can have one or more mirrors hosted on different git hosts, the most official one should be*origin*
34+
-`git clone` would implicitly name remote to*origin*
35+
-`upstream`: if current repository is a fork of another, the one been forked should be named as`upstream`.
36+
37+
##Remote Identifier
38+
39+
-**full uri**: such as`git@github.com:NixOS/nixpkgs`
40+
-**remote name**: such as`origin`
41+
42+
##Remote Branch Identifier
43+
44+
-`<remote_name>/<branch_name>`
45+
-`<branch_name>@{upstream}` or`<branch_name>@{u}`: attached remote branch of`<branch_name>`**on local**.
46+
-`@{upstream}` or`@{u}`: attached remote branch of**current branch**(if you're on a branch)
47+
48+
##Pull
49+
50+
`git pull <remote_name> <branch_name>`
51+
52+
```sh
53+
git branch -u<remote_name>/<branch_name> [<local_branch>]# make sure you have one upstream attached to the branch
54+
git pull# pull remote commit from the attached upstream to current branch
55+
```

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp