Skip to content

Commit bd728e9

Browse files
committed
main
1 parent e7bbe68 commit bd728e9

File tree

6 files changed

+271
-23
lines changed

6 files changed

+271
-23
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Overview
2+
3+
- **Changes & Status**:
4+
- a file can be *tracked* or *untracked* which indicates whether the file is recognized by git as part of the repository.
5+
- a change includes *added*, *deleted*, *modified* at the minimum unit of lines.
6+
- 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*.
8+
- 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.
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# Commit
2+
3+
Commits are snapshots for each phase of the repository, which allowing you to rollback to any instance of that commit.
4+
Git is able to compare base on two commits(usually the current and last commit), which is the diff.
5+
6+
- Each commit stores a snapshot of current repository with a unique hash to be identified.
7+
- A commit can have **one or more** parent from which it was derived.
8+
- Each snapshot file or folder has a unique hash, and can inspect their content in some way.
9+
- the folder snapshot is called `tree`
10+
- the file snapshot is `blob`
11+
- a commit always shows the snapshot of root of the repository as entry of a commit
12+
13+
> [!NOTE]
14+
> *Revision* is another synonym of *Commit* in git.
15+
16+
> [!IMPORTANT]
17+
> **Commit** is the atomic identifier of how git manage the versions, it's the *true* and *real* concept while *branch* and *merge* are just *fake* concepts upon it.
18+
19+
## Commit Identifier
20+
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 hash on git commands.
22+
Each snapshot instance of that particular commit could be found on `.git/objects/<first-2digits-of-hash>/<restof-hash>`
23+
24+
> [!NOTE]
25+
> Those *identifier* of commits are called *refs* in git, you could find their representations in `.git/refs`
26+
27+
1. **commit hash**: the most explicit identification of a commit.
28+
2. **branch name**: points to **latest** commit of the branch.
29+
3. **tag name**: points to the commit of that tag.
30+
4. `HEAD` or `@`: points to the **current** commit you're at.
31+
- for some other special identifier names, see documentation.
32+
5. `-` or `@{-1}`: previous commit you're at.
33+
- `-` is not a valid identifier in some scenarios, but you can use it in like `git checkout -` or `git merge -`.
34+
6. **commit expression**: see next section.
35+
36+
### Commit Expression
37+
38+
Commit expression is special syntax to reference commits backward from a given point.
39+
Three special symbols for traversing back in git:
40+
41+
1. `@`: reference backward through ***reflog***, you can see such symbol like `HEAD@{1}` in `git reflog` output.
42+
- `@{-<n>}`: go to nth previously checked out commit by `git checkout`
43+
- `<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+
2. `~`: trace back to previous commits through **the first parent** only.
46+
- `<identifier>~3`: points to previous 3 commit from current branch.
47+
3. `^`: trace back to previous commits through a specified parent by its index.
48+
- `<identifier>^2`: points to previous commit through **second** parent of `<identifier>`.
49+
- `<identifier>^101`: if you're wild enough to merge from 100 branches, you might need to point to previous commit through the 101-th parent.
50+
51+
> [!TIP]
52+
> `~1` and `^1` are always equivalent since they would pick the same first parent of the commit.
53+
54+
> [!NOTE]
55+
> See `git help revisions` for more details
56+
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+
>```
65+
66+
## Commit Inspection
67+
68+
Commit inspection generally requires `git cat-file -p <hash>`, see `git help cat-file`.
69+
70+
A commit can contain elements:
71+
- `tree`: the structure of current snapshot, including files and folders.
72+
- `parent`: the parent commit it was derived from, a commit can have multiple parents.
73+
- `author`: who did the changes.
74+
- `committer`: who made the commit, may differ from `author` when rebasing.
75+
- and more...
76+
77+
```console
78+
$ git cat-file -p 5eb5a747cfd9b17603b79d7ab64fc4ecee1751e3
79+
80+
tree e060913d1a04d39082981dc116c5a5cd35ba8e52
81+
parent 02348ec70c2c901e9ecc4be5860330e6dcf911ff
82+
author sharpchen <[email protected]> 1749697268 +0800
83+
committer sharpchen <[email protected]> 1749697268 +0800
84+
```
85+
86+
> [!TIP]
87+
> It's more general to use `git show <commit_identifier>` to inspect a commit.
88+
89+
### Tree & Blob Inspection
90+
91+
Tree in the inspected commit is a **recursive** structure and also has a hash that can be inspected by `git cat-file -p <hash>`.
92+
A `blob` represents a real file, a `tree` represents a folder as a container.
93+
So the tree printed from the commit is actually **the root folder of your repository**.
94+
95+
```console
96+
$ git cat-file -p e060913d1a04d39082981dc116c5a5cd35ba8e52
97+
98+
100644 blob 397b4a7624e35fa60563a9c03b1213d93f7b6546 .gitignore
99+
100644 blob 67f24d19be001eebf7bcdde488d8ab594bcd969d PSScriptAnalyzerSettings.psd1
100+
100644 blob 4bd5bb6fcff0b514d0160f3cb8ff01b5de46eeb4 README.md
101+
100644 blob 207846dc4b8f93edd892df9b6058ded48f5355b8 dotfiles.ps1
102+
100755 blob fa9fe71978d17992a3f27eaf78f2619a25a1966d dotfiles.sh
103+
040000 tree 0199c6476a45a6dadadaf7baf70a136d7f8f217f dotfiles
104+
100644 blob b6e1531298fed5dc7a019f6c01018b5c1add3c99 flake.lock
105+
100644 blob 92d9549668557adb021f959f8b898ad96ee84efb flake.nix
106+
100644 blob bb166d071cb8541aac7df35b7c1f5dbf420dd70c home.nix
107+
100644 blob baa979aff962214ddb5e23502acdb211d8d32064 install.ps1
108+
040000 tree c1aef838a425cd6f209ecc01f28bef2208fd2d26 packages
109+
```
110+
111+
You can either go deeper to the nested `tree` or inspect the snapshot content of a `blob` using the same way.
112+
113+
```console
114+
$ git cat-file -p 67f24d19be001eebf7bcdde488d8ab594bcd969d
115+
116+
@{
117+
IncludeRules = @('PSAvoidTrailingWhitespace')
118+
}
119+
```
120+
121+
## Checkout Commit
122+
123+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Git History & Reset
2+
3+
- `git log`: commit logs that can be synchronized with remotes.
4+
- `git reflog`: local operation logs which is more detailed but limited to local repository.
5+
- **dynamic pointers** such as `HEAD` and branches have their dedicated reflog on their own.
6+
7+
## Commit History Query
8+
9+
- `-<n>`: limits count of commit logs
10+
- `--skip=<n>`: skip count
11+
- ..., see: `git help log` in *Commit Limiting* section
12+
13+
### History Exclusion
14+
15+
Use `^` to exclude commits from certain points, such as `git log ^main foo` to exclude commits from `main` but keep commits from `foo`.
16+
17+
Example: show commits within branch `pwsh_es` but not in `master`:
18+
```console
19+
$ git log ^master pwsh_es
20+
* e8284ebb96d8 (origin/pwsh_es, pwsh_es) maintainers: add sharpchen
21+
* c0c964d8ae68 powershell-editor-services: init at 4.1.0
22+
23+
$ git log master..pwsh_es
24+
* e8284ebb96d8 (origin/pwsh_es, pwsh_es) maintainers: add sharpchen
25+
* c0c964d8ae68 powershell-editor-services: init at 4.1.0
26+
```
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
- branch name
13+
- `@{upstream}` or `@{u}`: refer to the local upstream
14+
15+
## Branch Inspection
16+
17+
A branch has its dedicated text file containing its latest commit hash at `./.git/refs/heads/<branch>`
18+
19+
```console
20+
$ cat ./.git/refs/heads/msbuid_ls
21+
4bfbc0c67e39f5615e0cdc4535611af1e71040d8
22+
```
23+
24+
If the latest commit hash is the only thing the branch knows, how could it collect all of the commits when git requires to?
25+
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.
26+
27+
## Branch Manipulation
28+
29+
> [!NOTE]
30+
> See `git help branch` and `tldr git-branch`.
31+
> Or `git help switch` and `tldr git-switch`.
32+
33+
- `git branch`
34+
- `-d|--delete`: delete branch
35+
- `-m|--move`: rename branch
36+
- `-c|--copy`: copy branch
37+
38+
## Merging
39+
40+
### Fast-Forward & Three-way Merging
41+
42+

docs/document/Skill/PowerShell/docs/Language/Array.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ $foo = @() # empty array
3232
>
3333
>$(1,2,3).Length # 3 this has different semantic but with same result
3434
>
35-
>(,(1,2,3)).Length # 3 # does spread items # [!code highlight]
35+
>(,(1,2,3)).Length # 3 # does spread items # [!code highlight]
3636
>
37-
>(,@(1,2,3)).Length # 1 # does not spread items # [!code highlight]
37+
>(,@(1,2,3)).Length # 1 # does not spread items # [!code highlight]
3838
>
39-
>((gci), (gci ..)).Length # 2 # [!code highlight]
39+
>((gci), (gci ..)).Length # 2 # [!code highlight]
4040
> ```
4141
4242
### From Expression and Statement
@@ -72,15 +72,15 @@ $foo = @{
7272
Age = 18
7373
}
7474
75-
@($foo.GetEnumerator()).Length # 2, System.Collections.DictionaryEntry from the HashTable # [!code highlight]
75+
@($foo.GetEnumerator()).Length # 2, System.Collections.DictionaryEntry from the HashTable # [!code highlight]
7676
```
7777

7878
### From Range
7979

8080
Range operator can create array from integer range and character range inclusively from both sides.
8181

8282
> [!NOTE]
83-
> character range was added in PowerShell 6
83+
> character range was added in PowerShell 6
8484
8585
```ps1
8686
1..10 # 1 to 10 inclusively
@@ -128,7 +128,7 @@ Use `*` to repeat the array content for certain times.
128128
((1,2,3) * 3).Length # 9
129129
```
130130

131-
A pratical usage of repetition is initialization with same value to the whole array.
131+
A practical usage of repetition is initialization with same value to the whole array.
132132

133133
```ps1
134134
@(255) * 100 # Fill up array sized 100 with 255 to all elements
@@ -165,9 +165,9 @@ Separate different ranges by `+` to generate a range union.
165165
(1..10)[0..2+4..5+7]
166166
```
167167

168-
## Substration
168+
## Subtraction
169169

170-
To substract a collection from another collection, you can certainly use `LINQ` or use a simple pipeline.
170+
To subtract a collection from another collection, you can certainly use `LINQ` or use a simple pipeline.
171171

172172
```ps1
173173
@(1,2,3) | where { @(1, 2) -notcontains $_ } # 3
@@ -204,7 +204,7 @@ $arr = 1,2,3
204204
205205
$arr -eq $null # empty array
206206
207-
$null -eq $arr # False, the result we expected # [!code highlight]
207+
$null -eq $arr # False, the result we expected # [!code highlight]
208208
```
209209

210210
> [!TIP]
@@ -247,7 +247,7 @@ Keyword operators has special functionalities on collections.
247247

248248
```ps1
249249
$a, $b, $c = 1,2,3 # $a = 1, $b = 2, $c = 3
250-
$a, $b = 1,2,3 # $a = 1, $b = 3 This might not be expected # [!code warning]
250+
$a, $b = 1,2,3 # $a = 1, $b = 3 This might not be expected # [!code warning]
251251
```
252252

253253
> [!WARNING]

0 commit comments

Comments
 (0)