|
1 | | -## Git 使用笔记 |
2 | | -<div id="header" align="center"> |
3 | | - <img src="https://media.giphy.com/media/du3J3cXyzhj75IOgvA/giphy.gif" width="120"/> |
4 | | -</div> |
5 | | - |
6 | | -#### 1.网络连接问题 |
7 | | - |
8 | | -无法连接的时候可以使用clash-verge的全局代理 |
9 | | -Git配置参考:[Git配置文档参考](https://git.javaliu.com/02_config/03_remote_config.html)。 |
10 | | -<img src="C:\Users\han\AppData\Roaming\Typora\typora-user-images\image-20250421011829645.png" alt="image-20250421011829645" style="zoom:30%;" /> |
11 | | - |
12 | | -```bash |
13 | | -复制bash环境变量类型:like this ,then excute it in wsl bash |
14 | | -export https_proxy=http://127.0.0.1:7897 http_proxy=http://127.0.0.1:7897 all_proxy=socks5://127.0.0.1:7897 |
15 | | -# 修改 ~/.bashrc |
16 | | -# 增加上面的语句 |
17 | | -``` |
18 | | - |
19 | | -```bash |
20 | | -# 主要分为 global 和 local 两种 ,这里个人开发就选择 global 比较简单 |
21 | | -git config --global --unset https.proxy |
22 | | -git config --global --unset http.proxy |
23 | | -``` |
24 | | - |
25 | | -*** |
26 | | - |
27 | | -#### 2.diverged(分叉问题) |
28 | | - |
29 | | -本地分支和远程分支已经分叉(diverged),也就是说,它们各自有了独立的提交历史。Git 不知道你希望如何处理这种分歧:是通过合并(merge)还是通过变基(rebase)来整合这些更改。 |
30 | | - |
31 | | -```bash |
32 | | -由于git默认的merge策略,我采用rebase(这种方式可以是提交呈现线性的),不会导致merge的分支看起来太乱 |
33 | | -git config pull.rebase true # 修改默认改为rebase |
34 | | -git pull --rebase origin update # 手动指定rebase |
35 | | -# 出现rebase conflict |
36 | | -git rebase --continue # 手动解决冲突 |
37 | | -``` |
38 | | - |
39 | | - |
40 | | - |
41 | | - |
42 | | - |
43 | | -#### 4.分支clone问题 |
44 | | - |
45 | | -```bash |
46 | | -# 一般情况下,clone项目地址后,只会clone main 分支的内容 |
47 | | -# 如何clone 其他指定分支呢 eg: brach -> myfeature |
48 | | -git clone -b myfeature https://github.com/pwxiao/AutoOJ.git |
49 | | -``` |
50 | | - |
51 | | - |
52 | | - |
53 | | -#### 3.Git工作流 |
54 | | - |
55 | | -```bash |
56 | | -# github workflow |
57 | | -git clone ** |
58 | | -git checkout -b myfeature |
59 | | -# git diff # check what change you did |
60 | | -git add . |
61 | | -git commit "filename" -m "提交信息" |
62 | | -git push origin myfeature |
63 | | -git checkout main |
64 | | -git pull origin main |
65 | | -git checkout myfeature |
66 | | -git rebase main |
67 | | -# may be had rebase conflict |
68 | | -# you should choice what segement you need. |
69 | | -git push -f origin myfeature |
70 | | -git checkout myfeature |
71 | | -# everthing ready! |
72 | | -# pull request |
73 | | -# main branch user will use squash and merge |
74 | | -# update2 |
75 | | -**delete branch** |
76 | | -**git checkout main** |
77 | | -**git branch -D myfeature** |
78 | | -git pull origin master **new result** |
79 | | -``` |
80 | | - |
81 | | -#### 4.对Git进行代码打包->zip,tar.gz, |
82 | | - |
83 | | -```bash |
84 | | -git archive --format=zip --output=/home/han/OJ/Autooj.zip HEAD |
85 | | -# 在当前分支的head位置进行代码打包,这里的格式是zip |
86 | | -git log main --oneline # 查看main分支的hash值 |
87 | | -``` |
88 | | - |
89 | | -#### 5.对于git修改当前分支,切换分支不变的情况 |
90 | | - |
91 | | -问题描述:我在A分支上面做了修改,然后切换到B分支的时候,发现B分支上也存在A分支上面的修改 |
92 | | -问题原因:如果当前分支所作的修改没有提交就切换其他的分支的话,那么分支上也会看到相同的修改 |
93 | | - |
94 | | -```bash |
95 | | -1:解决方法一 |
96 | | -git add . |
97 | | -git commit -m "commit_message" |
98 | | -git status # 检查工作区和暂存区是不是干净的 |
99 | | -# 如下图所示 |
100 | | -``` |
101 | | - |
102 | | -<img src="https://iocion.github.io/image-bed/image/Git%E4%BD%BF%E7%94%A8%E7%AC%94%E8%AE%B0workdflow.png" alt="image-20250428182724646" style="zoom:100%;" /> |
103 | | - |
104 | | -```bash |
105 | | -2:解决方法二 |
106 | | -# 如果在当前的分支工作还没有做完,不能提交,但是又想去其他的分支,这时可以把当前分支的工作现场隐藏起来。使用git stash隐藏当前的工作现场,这时候使用git status查看工作区是否是干净的,就可以放心去其他分支的部分了。使用git stash list 可以查看隐藏的工作现场 |
107 | | -恢复工作现场的两种方式 |
108 | | -1.用 git stash apply 恢复。恢复后,stash list 中并不删除恢复的stash,需要使用 git stash drop 来删除。 |
109 | | -2.用 git stash pop,恢复的时候,先用 git stash list 查看,然后使用 git stash apply stash@{0} |
110 | | -or git stash pop stash@{0} 来恢复指定的 stash |
111 | | -``` |
112 | | - |
113 | | -<img src="https://iocion.github.io/image-bed/image/Git使用笔记.png" alt="image-20250428182724646" style="zoom:100%;" /> |
114 | | - |
115 | | -#### 6.使用git stash进行隐藏修改 |
116 | | -```bash |
117 | | -1.使用git stash <filename> |
118 | | -2.git stash pop 回到上面一个状态 |
119 | | -``` |
120 | | - |
121 | | - |
122 | | -#### 7.使用增加.gitignore放置提交杂项文件 |
123 | | -(template here)<https://github.com/github/gitignore> |
124 | | - |
125 | | - |
126 | | -#### 8.如果commit重要信息怎么回退 |
127 | | -```bash |
128 | | -# 查看帮助git --help [command] |
129 | | -git checkout (git老版本) |
130 | | -git restore |
131 | | -git revert |
132 | | -git reset |
133 | | -``` |
134 | | -#### 8.git连接总是失败的问题解决 |
135 | | - |
136 | | -```bash |
137 | | -export -p # |
138 | | -##declare -x http_proxy="http://127.0.0.1:7897" |
139 | | -declare -x https_proxy="http://127.0.0.1:7897" |
140 | | -## |
141 | | -unset http_proxy |
142 | | -unset https_proxy |
143 | | -``` |
144 | | - |
145 | | -#### 9.查看git日志内容 |
146 | | - |
147 | | -```bash |
148 | | -git reflog # 可以查看git使用执行命令commit rebase fetch merge 的详细信息 |
149 | | -``` |
150 | | - |
151 | | -#### 10.github出现小箭头 |
152 | | - |
153 | | -```bash |
154 | | -出现原因:文件夹目录下面存在多余的.git/文件夹,github识别它为仓库,提交之后显示白色箭头。 |
155 | | -解决方法: |
156 | | - 删除多余的.git文件夹,同时使用 |
157 | | - git rm --cached [folder_name],进行缓存的清理,对上一个.git的配置进行reload |
158 | | - git commit -m "commit-message" |
159 | | -``` |
160 | | - |
161 | | - |
162 | | - |
163 | | -<span id="busuanzi_container_page_pv">文章总观看量<span id="busuanzi_value_page_pv"></span>次</span> |
| 1 | +## Git 使用笔记 |
| 2 | +<div id="header" align="center"> |
| 3 | + <img src="https://media.giphy.com/media/du3J3cXyzhj75IOgvA/giphy.gif" width="120"/> |
| 4 | +</div> |
| 5 | + |
| 6 | +#### 1.网络连接问题 |
| 7 | + |
| 8 | +无法连接的时候可以使用clash-verge的全局代理 |
| 9 | +Git配置参考:[Git配置文档参考](https://git.javaliu.com/02_config/03_remote_config.html)。 |
| 10 | +<img src="C:\Users\han\AppData\Roaming\Typora\typora-user-images\image-20250421011829645.png" alt="image-20250421011829645" style="zoom:30%;" /> |
| 11 | + |
| 12 | +```bash |
| 13 | +复制bash环境变量类型:like this ,then excute it in wsl bash |
| 14 | +export https_proxy=http://127.0.0.1:7897 http_proxy=http://127.0.0.1:7897 all_proxy=socks5://127.0.0.1:7897 |
| 15 | +# 修改 ~/.bashrc |
| 16 | +# 增加上面的语句 |
| 17 | +``` |
| 18 | + |
| 19 | +```bash |
| 20 | +# 主要分为 global 和 local 两种 ,这里个人开发就选择 global 比较简单 |
| 21 | +git config --global --unset https.proxy |
| 22 | +git config --global --unset http.proxy |
| 23 | +``` |
| 24 | + |
| 25 | +*** |
| 26 | + |
| 27 | +#### 2.diverged(分叉问题) |
| 28 | + |
| 29 | +本地分支和远程分支已经分叉(diverged),也就是说,它们各自有了独立的提交历史。Git 不知道你希望如何处理这种分歧:是通过合并(merge)还是通过变基(rebase)来整合这些更改。 |
| 30 | + |
| 31 | +```bash |
| 32 | +由于git默认的merge策略,我采用rebase(这种方式可以是提交呈现线性的),不会导致merge的分支看起来太乱 |
| 33 | +git config pull.rebase true # 修改默认改为rebase |
| 34 | +git pull --rebase origin update # 手动指定rebase |
| 35 | +# 出现rebase conflict |
| 36 | +git rebase --continue # 手动解决冲突 |
| 37 | +``` |
| 38 | + |
| 39 | + |
| 40 | + |
| 41 | + |
| 42 | + |
| 43 | +#### 4.分支clone问题 |
| 44 | + |
| 45 | +```bash |
| 46 | +# 一般情况下,clone项目地址后,只会clone main 分支的内容 |
| 47 | +# 如何clone 其他指定分支呢 eg: brach -> myfeature |
| 48 | +git clone -b myfeature https://github.com/pwxiao/AutoOJ.git |
| 49 | +``` |
| 50 | + |
| 51 | + |
| 52 | + |
| 53 | +#### 3.Git工作流 |
| 54 | + |
| 55 | +```bash |
| 56 | +# github workflow |
| 57 | +git clone ** |
| 58 | +git checkout -b myfeature |
| 59 | +# git diff # check what change you did |
| 60 | +git add . |
| 61 | +git commit "filename" -m "提交信息" |
| 62 | +git push origin myfeature |
| 63 | +git checkout main |
| 64 | +git pull origin main |
| 65 | +git checkout myfeature |
| 66 | +git rebase main |
| 67 | +# may be had rebase conflict |
| 68 | +# you should choice what segement you need. |
| 69 | +git push -f origin myfeature |
| 70 | +git checkout myfeature |
| 71 | +# everthing ready! |
| 72 | +# pull request |
| 73 | +# main branch user will use squash and merge |
| 74 | +# update2 |
| 75 | +**delete branch** |
| 76 | +**git checkout main** |
| 77 | +**git branch -D myfeature** |
| 78 | +git pull origin master **new result** |
| 79 | +``` |
| 80 | + |
| 81 | +#### 4.对Git进行代码打包->zip,tar.gz, |
| 82 | + |
| 83 | +```bash |
| 84 | +git archive --format=zip --output=/home/han/OJ/Autooj.zip HEAD |
| 85 | +# 在当前分支的head位置进行代码打包,这里的格式是zip |
| 86 | +git log main --oneline # 查看main分支的hash值 |
| 87 | +``` |
| 88 | + |
| 89 | +#### 5.对于git修改当前分支,切换分支不变的情况 |
| 90 | + |
| 91 | +问题描述:我在A分支上面做了修改,然后切换到B分支的时候,发现B分支上也存在A分支上面的修改 |
| 92 | +问题原因:如果当前分支所作的修改没有提交就切换其他的分支的话,那么分支上也会看到相同的修改 |
| 93 | + |
| 94 | +```bash |
| 95 | +1:解决方法一 |
| 96 | +git add . |
| 97 | +git commit -m "commit_message" |
| 98 | +git status # 检查工作区和暂存区是不是干净的 |
| 99 | +# 如下图所示 |
| 100 | +``` |
| 101 | + |
| 102 | +<img src="https://iocion.github.io/image-bed/image/Git%E4%BD%BF%E7%94%A8%E7%AC%94%E8%AE%B0workdflow.png" alt="image-20250428182724646" style="zoom:100%;" /> |
| 103 | + |
| 104 | +```bash |
| 105 | +2:解决方法二 |
| 106 | +# 如果在当前的分支工作还没有做完,不能提交,但是又想去其他的分支,这时可以把当前分支的工作现场隐藏起来。使用git stash隐藏当前的工作现场,这时候使用git status查看工作区是否是干净的,就可以放心去其他分支的部分了。使用git stash list 可以查看隐藏的工作现场 |
| 107 | +恢复工作现场的两种方式 |
| 108 | +1.用 git stash apply 恢复。恢复后,stash list 中并不删除恢复的stash,需要使用 git stash drop 来删除。 |
| 109 | +2.用 git stash pop,恢复的时候,先用 git stash list 查看,然后使用 git stash apply stash@{0} |
| 110 | +or git stash pop stash@{0} 来恢复指定的 stash |
| 111 | +``` |
| 112 | + |
| 113 | +<img src="https://iocion.github.io/image-bed/image/Git使用笔记.png" alt="image-20250428182724646" style="zoom:100%;" /> |
| 114 | + |
| 115 | +#### 6.使用git stash进行隐藏修改 |
| 116 | +```bash |
| 117 | +1.使用git stash <filename> |
| 118 | +2.git stash pop 回到上面一个状态 |
| 119 | +``` |
| 120 | + |
| 121 | + |
| 122 | +#### 7.使用增加.gitignore放置提交杂项文件 |
| 123 | +(template here)<https://github.com/github/gitignore> |
| 124 | + |
| 125 | + |
| 126 | +#### 8.如果commit重要信息怎么回退 |
| 127 | +```bash |
| 128 | +# 查看帮助git --help [command] |
| 129 | +git checkout (git老版本) |
| 130 | +git restore |
| 131 | +git revert |
| 132 | +git reset |
| 133 | +``` |
| 134 | +#### 8.git连接总是失败的问题解决 |
| 135 | + |
| 136 | +```bash |
| 137 | +export -p # |
| 138 | +##declare -x http_proxy="http://127.0.0.1:7897" |
| 139 | +declare -x https_proxy="http://127.0.0.1:7897" |
| 140 | +## |
| 141 | +unset http_proxy |
| 142 | +unset https_proxy |
| 143 | +``` |
| 144 | + |
| 145 | +#### 9.查看git日志内容 |
| 146 | + |
| 147 | +```bash |
| 148 | +git reflog # 可以查看git使用执行命令commit rebase fetch merge 的详细信息 |
| 149 | +``` |
| 150 | + |
| 151 | +#### 10.github出现小箭头 |
| 152 | + |
| 153 | +```bash |
| 154 | +出现原因:文件夹目录下面存在多余的.git/文件夹,github识别它为仓库,提交之后显示白色箭头。 |
| 155 | +解决方法: |
| 156 | + 删除多余的.git文件夹,同时使用 |
| 157 | + git rm --cached [folder_name],进行缓存的清理,对上一个.git的配置进行reload |
| 158 | + git commit -m "commit-message" |
| 159 | +``` |
| 160 | + |
| 161 | +#### github如何重新更新url |
| 162 | +``` |
| 163 | +git remote set-url origin [url] |
| 164 | +``` |
| 165 | + |
| 166 | +<span id="busuanzi_container_page_pv">文章总观看量<span id="busuanzi_value_page_pv"></span>次</span> |
0 commit comments