0%

git配置使用解析

注释

跟python的注释一样都是以#开头

.gitignore

忽略某一个文件夹但是不忽略某个文件

其他操作

从仓库中删除一个已经被添加到版本管理里面的文件

查看已经添加到git版本管理中的文件

git ls-files

从仓库中删除某个文件

git rm -r --cached target

github与google drive双向同步

油猴脚本不能够直接与github同步尝试能不能导出到google drive,然后实现github与google drive双向同步,即可实现代码备份

启发文章

remote

引子

git clone可以方便的拉取一个远程仓库,但git clone有一个毛病,他会生成一个对应仓库名的文件夹A

此时拉取的源码将存放在这个文件夹A里面

如果需要直接保存源码在你想’git clone’的根目录下该如何做呢?

我遇到的需求是,我将自己的vscode setting备份在了github上,方便我多终端同步自己的vscode设置

这时候在另一个全新的设备上,需要拉取另外一个设备对setting做的修改

步骤

在需要拉取的目录下 git init

接着添加远程仓库的链接git remote add main <远程仓库的url>

设置默认的上传分支git branch --set-upstream-to=main/main

最后git pull就可以愉快的使用了

bug
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
C:\Users\lnd\AppData\Roaming\Code\User>git init
Initialized empty Git repository in C:/Users/lnd/AppData/Roaming/Code/User/.git/

C:\Users\lnd\AppData\Roaming\Code\User>git remote add https://github.com/ednow/vscode-setting.git
usage: git remote add [<options>] <name> <url>

-f, --fetch fetch the remote branches
--tags import all tags and associated objects when fetching
or do not fetch any tag at all (--no-tags)
-t, --track <branch> branch(es) to track
-m, --master <branch>
master branch
--mirror[=(push|fetch)]
set up remote as a mirror to push to or fetch from


C:\Users\lnd\AppData\Roaming\Code\User>git remote add main https://github.com/ednow/vscode-setting.git

C:\Users\lnd\AppData\Roaming\Code\User>git pull
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.

git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

git branch --set-upstream-to=main/<branch> main


C:\Users\lnd\AppData\Roaming\Code\User> git branch --set-upstream-to=main main
fatal: branch 'main' does not exist

C:\Users\lnd\AppData\Roaming\Code\User>git branch --set-upstream-to=main/main
fatal: branch 'main' does not exist

C:\Users\lnd\AppData\Roaming\Code\User>git branch

C:\Users\lnd\AppData\Roaming\Code\User>git branch main
fatal: Not a valid object name: 'main'.

C:\Users\lnd\AppData\Roaming\Code\User>git checkout -b main
Switched to a new branch 'main'

C:\Users\lnd\AppData\Roaming\Code\User>git branch --set-upstream-to=main/main
fatal: branch 'main' does not exist

C:\Users\lnd\AppData\Roaming\Code\User>git branch

C:\Users\lnd\AppData\Roaming\Code\User>git status
On branch main

No commits yet

Untracked files:
(use "git add <file>..." to include in what will be committed)
globalStorage/
settings.json
workspaceStorage/

nothing added to commit but untracked files present (use "git add" to track)

C:\Users\lnd\AppData\Roaming\Code\User>git branch --set-upstream-to=main/master
fatal: branch 'main' does not exist

C:\Users\lnd\AppData\Roaming\Code\User>git branch --set-upstream-to=master/main
fatal: branch 'main' does not exist

C:\Users\lnd\AppData\Roaming\Code\User>git commit -am "test"
On branch main

Initial commit

Untracked files:
(use "git add <file>..." to include in what will be committed)
globalStorage/
settings.json
workspaceStorage/

nothing added to commit but untracked files present (use "git add" to track)

C:\Users\lnd\AppData\Roaming\Code\User>git branch --set-upstream-to=main/main
fatal: branch 'main' does not exist

C:\Users\lnd\AppData\Roaming\Code\User>git pu;;
git: 'pu;;' is not a git command. See 'git --help'.

The most similar commands are
pull
push

C:\Users\lnd\AppData\Roaming\Code\User>git pull
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.

git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

git branch --set-upstream-to=main/<branch> main

应该使用如下步骤

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
C:\Users\lnd\AppData\Roaming\Code\User>git init
Initialized empty Git repository in C:/Users/lnd/AppData/Roaming/Code/User/.git/

C:\Users\lnd\AppData\Roaming\Code\User>git remote add main https://github.com/ednow/vscode-setting.git

C:\Users\lnd\AppData\Roaming\Code\User>git pull main main
remote: Enumerating objects: 189, done.
remote: Counting objects: 100% (189/189), done.
remote: Compressing objects: 100% (123/123), done.
Receiving objects: 78% (148/189)used 121 (delta 65), pack-reused 0 eceiving objects: 56% (106/189)
Receiving objects: 100% (189/189), 21.14 KiB | 618.00 KiB/s, done.
Resolving deltas: 100% (133/133), done.
From https://github.com/ednow/vscode-setting
* branch main -> FETCH_HEAD
* [new branch] main -> main/main
error: The following untracked working tree files would be overwritten by merge:
settings.json
Please move or remove them before you merge.
Aborting

C:\Users\lnd\AppData\Roaming\Code\User>git pull main main
From https://github.com/ednow/vscode-setting
* branch main -> FETCH_HEAD

-v

查看当前远程仓库地址

git remote -v

参考文献

rm

删除远程仓库连接

git remote rm origin

参考文献

rm

仅仅删除当前缓存区

1
2
3
4
git rm --cached "文件路径" # ,不删除物理文件,仅将该文件从缓存中删除;
git rm --f "文件路径" # ,不仅将该文件从缓存中删除,还会将物理文件删除(不会回收到垃圾桶);

git rm -r --cached "文件路径" # 删除文件夹

从历史记录中删除这个文件

1
git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch path-to-your-remove-file' --prune-empty --tag-name-filter cat -- --all

path-to-your-remove-file就是你需要删除的文件的路径

以强制覆盖的方式推送

git push origin master --force --all

进行垃圾回收

1
2
3
4
rm -rf .git/refs/original/
git reflog expire --expire=now --all
git gc --prune=now
git gc --aggressive --prune=now

参考文献

从git缓存区的仓库中删除一些文件

Git如何永久删除文件(包括历史记录)

根据hash值查看文件名

git rev-list --objects --all | grep 90c5365492dea3b3c855b2375f1de8588ac1bda4

git filter-branch —force —index-filter ‘git rm -r —cached —ignore-unmatch BV1hE411t7RN/vision/‘ —prune-empty —tag-name-filter cat — —all

跟换远程仓库

1
2
3
git remote rm origin
git remote add origin <你的新远程仓库地址>
git remote -v 查看当前仓库

保存用户名和密码

每次git pull都需要输密码,可以使用下面的命令记住登录凭证

git config --global credential.helper store

利用git action自动同步gitee和git action的代码

参考文章

参考文章

github 提交历史头像不正确显示

git config --global user.email "github邮箱"

解决方法:参考文献

查看自己的github邮箱参考文献

子模块的使用

参考文献

删除更新

删除

git rm --cached

参考文献

查看

git submodule status

参考文献

git lfs

git 最大文件为100mb

在git仓库中添加大文件

git lfs track "*.psd"

git add .gitattributes

参看git lfs的容量
参考文献

提交pr

参考文献

更改commit的comment

改了之后要先git pull再push?

图片详情找不到图片(Image not found)
图片详情找不到图片(Image not found)
图片详情找不到图片(Image not found)

一次push所有分支

参考文献

回退操作

参考文献

删除文件的找回

代码详情
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
(base) D:\Users\LND\Desktop\ereaseo\algorithms>gs
On branch main
Your branch is up to date with 'origin/main'.

Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: PTA/PTA1072/GasStation.cpp
deleted: PTA/PTA1072/GasStation.py

Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: CMakeLists.txt
modified: PTA/README.md

Untracked files:
(use "git add <file>..." to include in what will be committed)
"PTA/PTA1086/\346\265\213\350\257\225\347\202\271.pptx"
cmake-build-debug-coverage/
utils/hello.txt


(base) D:\Users\LND\Desktop\ereaseo\algorithms>git restore PTA/PTA1072/GasStation.py
error: pathspec 'PTA/PTA1072/GasStation.py' did not match any file(s) known to git

(base) D:\Users\LND\Desktop\ereaseo\algorithms>dir
驱动器 D 中的卷没有标签。
卷的序列号是 B84E-7A0C

D:\Users\LND\Desktop\ereaseo\algorithms 的目录

2021/08/20 16:17 <DIR> .
2021/08/20 16:17 <DIR> ..
2021/07/01 19:08 337 .gitignore
2021/08/20 16:18 <DIR> .idea
2021/06/29 14:22 <DIR> .vs
2021/06/20 22:59 <DIR> CCF-CSP
2021/08/20 16:18 <DIR> cmake-build-debug
2021/08/20 16:18 <DIR> cmake-build-debug-coverage
2021/08/20 16:17 1,705 CMakeLists.txt
2021/08/20 15:47 171 config.json
2021/07/19 00:04 <DIR> examples
2021/07/01 05:54 <DIR> googletest
2021/06/25 23:51 <DIR> json
2021/06/30 08:16 17,098 LICENSE
2021/07/19 00:04 176 main.cpp
2021/06/30 08:05 951 Main.java
2021/08/15 14:19 3,856 main.py
2021/07/10 15:35 <DIR> MISC
2021/06/27 16:16 <DIR> out
2021/06/25 13:49 966 pom.xml
2021/08/20 16:16 <DIR> PTA
2021/08/15 14:23 2,334 README.md
2021/06/24 18:24 <DIR> target
2021/06/29 12:23 0 temp.cpp
2021/06/26 00:04 12 temp.txt
2021/08/19 19:00 <DIR> utils
2021/07/06 16:17 0 __init__.py
12 个文件 27,606 字节
15 个目录 115,732,488,192 可用字节

(base) D:\Users\LND\Desktop\ereaseo\algorithms>git checkout PTA/PTA1072/GasStation.py
error: pathspec 'PTA/PTA1072/GasStation.py' did not match any file(s) known to git

(base) D:\Users\LND\Desktop\ereaseo\algorithms>git checkout PTA\PTA1072\GasStation.py
error: pathspec 'PTA\PTA1072\GasStation.py' did not match any file(s) known to git

(base) D:\Users\LND\Desktop\ereaseo\algorithms>git checkout PTA\\PTA1072\\GasStation.py
error: pathspec 'PTA\\PTA1072\\GasStation.py' did not match any file(s) known to git

(base) D:\Users\LND\Desktop\ereaseo\algorithms>git restore --staged PTA/PTA1072/GasStation.py

(base) D:\Users\LND\Desktop\ereaseo\algorithms>gs
On branch main
Your branch is up to date with 'origin/main'.

Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: PTA/PTA1072/GasStation.cpp

Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: CMakeLists.txt
deleted: PTA/PTA1072/GasStation.py
modified: PTA/README.md

Untracked files:
(use "git add <file>..." to include in what will be committed)
"PTA/PTA1086/\346\265\213\350\257\225\347\202\271.pptx"
cmake-build-debug-coverage/
utils/hello.txt


(base) D:\Users\LND\Desktop\ereaseo\algorithms>git checkout PTA\\PTA1072\\GasStation.py
Updated 1 path from the index

(base) D:\Users\LND\Desktop\ereaseo\algorithms>

参考好像讲的都不对?为什么我要先unstage。?

参考文献

参考文献

submodule

图片详情找不到图片(Image not found)

参考文献

无权限

代码详情
1
2
3
4
5
6
7
8
9
On branch main
nothing to commit, working tree clean
fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

C:\Users\lnd\AppData\Roaming\Code\User>
代码详情
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
Microsoft Windows [版本 10.0.19043.1165]
(c) Microsoft Corporation。保留所有权利。

C:\Users\lnd\AppData\Roaming\Code\User>git init
Initialized empty Git repository in C:/Users/lnd/AppData/Roaming/Code/User/.git/

C:\Users\lnd\AppData\Roaming\Code\User>git remote add main https://github.com/ednow/vscode-setting.git

C:\Users\lnd\AppData\Roaming\Code\User>git branch --set-upstream-to=main/main
fatal: branch 'main' does not exist

C:\Users\lnd\AppData\Roaming\Code\User>git status
On branch main

No commits yet

Untracked files:
(use "git add <file>..." to include in what will be committed)
.gitignore
keybindings.json
settings.json
snippets/

nothing added to commit but untracked files present (use "git add" to track)

C:\Users\lnd\AppData\Roaming\Code\User>sp save
On branch main

Initial commit

Untracked files:
(use "git add <file>..." to include in what will be committed)
.gitignore
keybindings.json
settings.json
snippets/

nothing added to commit but untracked files present (use "git add" to track)
fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

C:\Users\lnd\AppData\Roaming\Code\User>git branch --set-upstream-to=main/main
fatal: branch 'main' does not exist

C:\Users\lnd\AppData\Roaming\Code\User>gs
On branch main

No commits yet

Untracked files:
(use "git add <file>..." to include in what will be committed)
.gitignore
keybindings.json
settings.json
snippets/

nothing added to commit but untracked files present (use "git add" to track)

C:\Users\lnd\AppData\Roaming\Code\User>git commit -am "sa"

C:\Users\lnd\AppData\Roaming\Code\User>git pull
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.

git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

git branch --set-upstream-to=main/<branch> main


C:\Users\lnd\AppData\Roaming\Code\User>git branch --set-upstream-to=main/main
fatal: branch 'main' does not exist

C:\Users\lnd\AppData\Roaming\Code\User>git commit -am "save"
On branch main

Initial commit

Untracked files:
(use "git add <file>..." to include in what will be committed)
.gitignore
keybindings.json
settings.json
snippets/

nothing added to commit but untracked files present (use "git add" to track)

C:\Users\lnd\AppData\Roaming\Code\User>ga

C:\Users\lnd\AppData\Roaming\Code\User>git pull
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.

git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

git branch --set-upstream-to=main/<branch> main


C:\Users\lnd\AppData\Roaming\Code\User>git branch --set-upstream-to=main/main
fatal: branch 'main' does not exist

C:\Users\lnd\AppData\Roaming\Code\User>gs

C:\Users\lnd\AppData\Roaming\Code\User>ga

C:\Users\lnd\AppData\Roaming\Code\User>git commit -am "save"
[main (root-commit) 5caa472] save
6 files changed, 776 insertions(+)
create mode 100644 .gitignore
create mode 100644 keybindings.json
create mode 100644 settings.json
create mode 100644 snippets/crg.code-snippets
create mode 100644 snippets/ednowMarkdownCode.code-snippets
create mode 100644 snippets/react.code-snippets

C:\Users\lnd\AppData\Roaming\Code\User>git branch --set-upstream-to=main/main
error: the requested upstream branch 'main/main' does not exist
hint:
hint: If you are planning on basing your work on an upstream
hint: branch that already exists at the remote, you may need to
hint: run "git fetch" to retrieve it.
hint:
hint: If you are planning to push out a new local branch that
hint: will track its remote counterpart, you may want to use
hint: "git push -u" to set the upstream config as you push.

C:\Users\lnd\AppData\Roaming\Code\User>git pull
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.

git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

git branch --set-upstream-to=main/<branch> main


C:\Users\lnd\AppData\Roaming\Code\User>git pull main main
remote: Enumerating objects: 189, done.
remote: Counting objects: 100% (189/189), done.
remote: Compressing objects: 100% (123/123), done.
remote: Total 189 (delta 133), reused 121 (delta 65), pack-reused 0R
Receiving objects: 100% (189/189), 21.14 KiB | 3.52 MiB/s, done.
Resolving deltas: 100% (133/133), done.
From https://github.com/ednow/vscode-setting
* branch main -> FETCH_HEAD
* [new branch] main -> main/main
fatal: refusing to merge unrelated histories

C:\Users\lnd\AppData\Roaming\Code\User>sp save
On branch main
nothing to commit, working tree clean
fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

C:\Users\lnd\AppData\Roaming\Code\User>git branch --set-upstream-to=main/main
Branch 'main' set up to track remote branch 'main' from 'main'.

C:\Users\lnd\AppData\Roaming\Code\User>git commit -am "save"
On branch main
Your branch and 'main/main' have diverged,
and have 1 and 46 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)

nothing to commit, working tree clean

C:\Users\lnd\AppData\Roaming\Code\User>git pull
fatal: refusing to merge unrelated histories

C:\Users\lnd\AppData\Roaming\Code\User>sp save
On branch main
Your branch and 'main/main' have diverged,
and have 1 and 46 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)

nothing to commit, working tree clean
fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

C:\Users\lnd\AppData\Roaming\Code\User>git push --force origin main
fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

C:\Users\lnd\AppData\Roaming\Code\User>git push --force main main
Enumerating objects: 9, done.
Counting objects: 100% (9/9), done.
Delta compression using up to 12 threads
Compressing objects: 100% (7/7), done.
Writing objects: 100% (9/9), 6.15 KiB | 6.15 MiB/s, done.
Total 9 (delta 1), reused 3 (delta 1), pack-reused 0
remote: Resolving deltas: 100% (1/1), done.
To https://github.com/ednow/vscode-setting.git
+ 7b6818b...5caa472 main -> main (forced update)

C:\Users\lnd\AppData\Roaming\Code\User>

坏方法

vscode配置同步问题的解决方案

代码详情
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
Microsoft Windows [版本 10.0.19043.985]
(c) Microsoft Corporation。保留所有权利。

C:\Users\46257\AppData\Roaming\Code\User>git init
Initialized empty Git repository in C:/Users/46257/AppData/Roaming/Code/User/.git/

C:\Users\46257\AppData\Roaming\Code\User>git remote

C:\Users\46257\AppData\Roaming\Code\User>git remote add https://github.com/ednow/vscode-setting.git
usage: git remote add [<options>] <name> <url>

-f, --fetch fetch the remote branches
--tags import all tags and associated objects when fetching
or do not fetch any tag at all (--no-tags)
-t, --track <branch> branch(es) to track
-m, --master <branch>
master branch
--mirror[=(push|fetch)]
set up remote as a mirror to push to or fetch from


C:\Users\46257\AppData\Roaming\Code\User>git remote add origin https://github.com/ednow/vscode-setting.git

C:\Users\46257\AppData\Roaming\Code\User>git pul
git: 'pul' is not a git command. See 'git --help'.

The most similar commands are
pull
push

C:\Users\46257\AppData\Roaming\Code\User>git pull
remote: Enumerating objects: 9, done.
remote: Counting objects: 100% (9/9), done.
remote: Compressing objects: 100% (7/7), done.
remote: Total 9 (delta 1), reused 9 (delta 1), pack-reused 0
Unpacking objects: 100% (9/9), 6.13 KiB | 56.00 KiB/s, done.
From https://github.com/ednow/vscode-setting
* [new branch] main -> origin/main
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.

git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

git branch --set-upstream-to=origin/<branch> master


C:\Users\46257\AppData\Roaming\Code\User>git pull main main
fatal: 'main' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

C:\Users\46257\AppData\Roaming\Code\User>git branch --set-upstream-to=origin/master
fatal: branch 'master' does not exist

C:\Users\46257\AppData\Roaming\Code\User>git branch --set-upstream-to=origin/ master
fatal: branch 'master' does not exist

C:\Users\46257\AppData\Roaming\Code\User>git pull origin main
From https://github.com/ednow/vscode-setting
* branch main -> FETCH_HEAD
error: The following untracked working tree files would be overwritten by merge:
keybindings.json
settings.json
Please move or remove them before you merge.
Aborting

C:\Users\46257\AppData\Roaming\Code\User>git pull origin main
From https://github.com/ednow/vscode-setting
* branch main -> FETCH_HEAD

C:\Users\46257\AppData\Roaming\Code\User>

参考文献

—allow-unrelated-histories

强制拉取无关的历史记录,如果没办法auto merge,且以远程仓库为准的话,清空冲突文件,再执行git pull --allow-unrelated-histories

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
sh-5.0# ls
_config.landscape.yml gitalk-init-cache.json node_modules python source
_config.yml gitalk-init-error.json package.json readme.md themes
draft gittalk-auto-init.js package-lock.json scaffolds yarn.lock
excel html ppt sitemap_template.xml
sh-5.0# cd ..
sh-5.0# ls
未命名.ipynb apkbuild cvs handtf singlepose test-cvp.py.log
algorithms Apkres examples-gpu mutilpose start.py vscodeUser
android blog facencnn sdl test-cvp.py workspace.code-workspace
sh-5.0# cd vscodeUser
sh-5.0# ls
globalStorage keybindings.json settings.json snippets state Workspaces workspaceStorage
sh-5.0# vim keybindings.json
sh-5.0# git pull
已经是最新的。
sh-5.0# rm -f -r .git
sh-5.0# ls -a
. .gitignore keybindings.json snippets Workspaces
.. globalStorage settings.json state workspaceStorage
sh-5.0# git init
已初始化空的 Git 仓库于 /root/.local/share/code-server/User/.git/
sh-5.0# git checkout -b main
切换到一个新分支 'main'
sh-5.0# git remote origin add https://github.com/ednow/vscode-setting.git
error: 未知子命令:origin
用法:git remote [-v | --verbose]
或:git remote add [-t <分支>] [-m <master>] [-f] [--tags | --no-tags] [--mirror=<fetch|push>] <名称> <地址>
或:git remote rename <旧名称> <新名称>
或:git remote remove <名称>
或:git remote set-head <名称> (-a | --auto | -d | --delete | <分支>)
或:git remote [-v | --verbose] show [-n] <名称>
或:git remote prune [-n | --dry-run] <名称>
或:git remote [-v | --verbose] update [-p | --prune] [(<组> | <远程>)...]
或:git remote set-branches [--add] <名称> <分支>...
或:git remote get-url [--push] [--all] <名称>
或:git remote set-url [--push] <名称> <新的地址> [<旧的地址>]
或:git remote set-url --add <名称> <新的地址>
或:git remote set-url --delete <名称> <地址>

-v, --verbose 冗长输出;必须置于子命令之前

sh-5.0# git remote main origin add https://github.com/ednow/vscode-setting.git
error: 未知子命令:main
用法:git remote [-v | --verbose]
或:git remote add [-t <分支>] [-m <master>] [-f] [--tags | --no-tags] [--mirror=<fetch|push>] <名称> <地址>
或:git remote rename <旧名称> <新名称>
或:git remote remove <名称>
或:git remote set-head <名称> (-a | --auto | -d | --delete | <分支>)
或:git remote [-v | --verbose] show [-n] <名称>
或:git remote prune [-n | --dry-run] <名称>
或:git remote [-v | --verbose] update [-p | --prune] [(<组> | <远程>)...]
或:git remote set-branches [--add] <名称> <分支>...
或:git remote get-url [--push] [--all] <名称>
或:git remote set-url [--push] <名称> <新的地址> [<旧的地址>]
或:git remote set-url --add <名称> <新的地址>
或:git remote set-url --delete <名称> <地址>

-v, --verbose 冗长输出;必须置于子命令之前

sh-5.0# git remote add https://github.com/ednow/vscode-setting.git
用法:git remote add [<选项>] <名称> <地址>

-f, --fetch 抓取远程的分支
--tags 抓取时导入所有的标签和关联对象
或不抓取任何标签(--no-tags)
-t, --track <分支> 跟踪的分支
-m, --master <分支> 主线分支
--mirror[=(push|fetch)]
把远程设置为用以推送或抓取的镜像

sh-5.0# git remote add -m origin https://github.com/ednow/vscode-setting.git
用法:git remote add [<选项>] <名称> <地址>

-f, --fetch 抓取远程的分支
--tags 抓取时导入所有的标签和关联对象
或不抓取任何标签(--no-tags)
-t, --track <分支> 跟踪的分支
-m, --master <分支> 主线分支
--mirror[=(push|fetch)]
把远程设置为用以推送或抓取的镜像

sh-5.0# git remote add -f origin https://github.com/ednow/vscode-setting.git
更新 origin 中
remote: Enumerating objects: 21, done.
remote: Counting objects: 100% (21/21), done.
remote: Compressing objects: 100% (12/12), done.
remote: Total 21 (delta 9), reused 20 (delta 8), pack-reused 0
展开对象中: 100% (21/21), 完成.
来自 https://github.com/ednow/vscode-setting
* [新分支] main -> origin/main
sh-5.0# git pull
当前分支没有跟踪信息。
请指定您要合并哪一个分支。
详见 git-pull(1)。

git pull <远程> <分支>

如果您想要为此分支创建跟踪信息,您可以执行:

git branch --set-upstream-to=origin/<分支> main

sh-5.0# git branch --set-upstream-to=origin main
fatal: 分支 'main' 不存在
sh-5.0# git checkout -b main
切换到一个新分支 'main'
sh-5.0# git branch --set-upstream-to=origin main
fatal: 分支 'main' 不存在
sh-5.0# git commit -am "save"
位于分支 main

初始提交

未跟踪的文件:
.gitignore
keybindings.json
settings.json
snippets/
state/

提交为空,但是存在尚未跟踪的文件
sh-5.0# git branch --set-upstream-to=origin main
fatal: 分支 'main' 不存在
sh-5.0# echo >> state/
sh: state/: 是一个目录
sh-5.0# echo state/ >> state
sh: state: 是一个目录
sh-5.0# echo state/ >> .gitignore
sh-5.0# tail .gitignore
workspaceStorage
globalStoragestate/
sh-5.0# echo 'state/' >> .gitignore
sh-5.0# tail .gitignore
workspaceStorage
globalStoragestate/
state/
sh-5.0# tail .gitignore^C
sh-5.0# git status
位于分支 main

尚无提交

未跟踪的文件:
(使用 "git add <文件>..." 以包含要提交的内容)

.gitignore
keybindings.json
settings.json
snippets/

提交为空,但是存在尚未跟踪的文件(使用 "git add" 建立跟踪)
sh-5.0# git add .
sh-5.0# git commit -am "save"
[main(根提交) 5c183bf] save
6 files changed, 65 insertions(+)
create mode 100644 .gitignore
create mode 100644 keybindings.json
create mode 100644 settings.json
create mode 100644 snippets/crg.code-snippets
create mode 100644 snippets/ednowMarkdownCode.code-snippets
create mode 100644 snippets/react.code-snippets
sh-5.0# git branch --set-upstream-to=origin main
error: 请求的上游分支 'origin' 不存在
提示:
提示:如果您正计划基于远程一个现存的上游分支开始你的工作,
提示:您可能需要执行 "git fetch" 来获取分支。
提示:
提示:如果您正计划推送一个能与对应远程分支建立跟踪的新的本地分支,
提示:您可能需要使用 "git push -u" 推送分支并配置和上游的关联。
sh-5.0# git remote add -f origin https://github.com/ednow/vscode-setting.git
fatal: 远程 origin 已经存在。
sh-5.0# git fetch
sh-5.0# git branch --set-upstream-to=origin main
error: 请求的上游分支 'origin' 不存在
提示:
提示:如果您正计划基于远程一个现存的上游分支开始你的工作,
提示:您可能需要执行 "git fetch" 来获取分支。
提示:
提示:如果您正计划推送一个能与对应远程分支建立跟踪的新的本地分支,
提示:您可能需要使用 "git push -u" 推送分支并配置和上游的关联。
sh-5.0# git branch --set-upstream-to=main main
warning: 未设置分支 main 作为它自己的上游。
sh-5.0# git branch --set-upstream-to=main m^C
sh-5.0# git pull
当前分支没有跟踪信息。
请指定您要合并哪一个分支。
详见 git-pull(1)。

git pull <远程> <分支>

如果您想要为此分支创建跟踪信息,您可以执行:

git branch --set-upstream-to=origin/<分支> main

sh-5.0# git pull main main
fatal: 'main' does not appear to be a git repository
fatal: 无法读取远程仓库。

请确认您有正确的访问权限并且仓库存在。
sh-5.0# git pull origin main
来自 https://github.com/ednow/vscode-setting
* branch main -> FETCH_HEAD
fatal: 拒绝合并无关的历史
sh-5.0# git pull origin main --allow-unrelated-histories
来自 https://github.com/ednow/vscode-setting
* branch main -> FETCH_HEAD
自动合并 snippets/ednowMarkdownCode.code-snippets
自动合并 settings.json
冲突(添加/添加):合并冲突于 settings.json
自动合并 keybindings.json
自动合并 .gitignore
冲突(添加/添加):合并冲突于 .gitignore
自动合并失败,修正冲突然后提交修正的结果。
sh-5.0# vim .gitignore
sh-5.0# rm settings.json
sh-5.0# rm .gitignore
sh-5.0# touch settings.json
sh-5.0# touch .gitignore.json
sh-5.0# git pull origin main --allow-unrelated-histories
error: 无法拉取,因为您有未合并的文件。
提示:请在工作区改正文件,然后酌情使用 'git add/rm <文件>' 命令标记
提示:解决方案并提交。
fatal: 因为存在未解决的冲突而退出。
sh-5.0# git reset --hard
HEAD 现在位于 5c183bf save
sh-5.0# vim .gitignore
sh-5.0# vim settings.json
sh-5.0# git commit -am "1"
位于分支 main
未跟踪的文件:
.gitignore.json

提交为空,但是存在尚未跟踪的文件
sh-5.0# rm .gitignore.json
sh-5.0# git pull origin main --allow-unrelated-histories
来自 https://github.com/ednow/vscode-setting
* branch main -> FETCH_HEAD
自动合并 snippets/ednowMarkdownCode.code-snippets
自动合并 settings.json
冲突(添加/添加):合并冲突于 settings.json
自动合并 keybindings.json
自动合并 .gitignore
冲突(添加/添加):合并冲突于 .gitignore
自动合并失败,修正冲突然后提交修正的结果。
sh-5.0# vim .gitignore

将闭源项目从此刻开始开源到另一个项目

由于历史的commit之中有一些敏感信息,所以我们需要开一个没有历史记录的分支

git checkout --orphan <新分支名>

然后将该分支推送到另一个仓库的特定分支上

先添加远程仓库的地址

git remote add <仓库名> <仓库url>

向添加的远程仓库的分支推送该分支

git push <仓库名> <本地分支>:<远程分支>

新建一个空白分支

git checkout --orphan <新分支名> && git rm -rf .

git删除分支

代码详情
1
2
3
4
5
// 删除本地分支
git branch -d <分支名称>

// 删除远程分支
git push origin --delete <分支名称>

git branch -d <分支名称> && git push origin --delete <分支名称>

git删除远程仓库

git remote rm origin

rebase和merge

参考文献

参考文献

将别的分支merge到当前分支

分支的新建与合并

git merge {branch name you want to merge}

添加多个远程连接

首先,先增加第一个地址 git remote add origin <url1>
然后增加第二个地址 git remote set-url --add origin <url2>
增加第三个地址 git remote set-url --add origin <url3>

git不支持只改fetch的url

参考文献

仓库讨论链接

push

代码详情
1
2
To have this happen automatically for branches without a tracking
upstream, see 'push.autoSetupRemote' in 'git help config'.

github

使用github api上传图片到指定仓库

lfs的错误

代码详情
1
2
3
4
Remote "origin" does not support the LFS locking API. Consider disabling it with:
$ git config lfs.https://github.com/ednow/images.git/info/lfs.locksverify false
Post "https://github.com/ednow/images.git/info/lfs/locks/verify": EOF
error: failed to push some refs to 'https://github.com/ednow/images.git'

git config lfs.https://github.com/ednow/images.git/info/lfs.locksverify false

branch

To see all remote branch names, run git branch -r:

To see all local and remote branches, run git branch -a:

git工具

用来看历史代码的工具git kraken

git修改提交作者和邮箱

参考文献

永久删除文件

git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch path-to-your-remove-file' --prune-empty --tag-name-filter cat -- --all

commit全部文件除了一个文件

参考文献

merge

如果要合master的话,需要去master分支拉取远程代码

参考文献

设置代理