8000 Update git.md · githubstatus/linux-command@f71227c · GitHub
[go: up one dir, main page]

Skip to content

Commit f71227c

Browse files
committed
Update git.md
1 parent 5aaf1eb commit f71227c

File tree

1 file changed

+33
-33
lines changed

1 file changed

+33
-33
lines changed

command/git.md

Lines changed: 33 additions & 33 deletions
< 9E88 /tr>
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ ssh -T git@github.com # 测试是否成功
162162

163163
`vim ~/.ssh/config` #修改config文件,如果没有创建 `config`
164164

165-
```shell
165+
```bash
166166
Host jslite.github.com
167167
HostName github.com
168168
User git
@@ -259,15 +259,15 @@ git clone https://github.com/username/rep.git
259259

260260
**1. 增加3个远程库地址**
261261

262-
```shell
262+
```bash
263263
git remote add origin https://github.com/JSLite/JSLite.git
264264
git remote set-url --add origin https://gitlab.com/wang/JSLite.js.git
265265
git remote set-url --add origin https://oschina.net/wang/JSLite.js.git
266266
```
267267

268268
**2. 删除其中一个 set-url 地址**
269269

270-
```shell
270+
```bash
271271
usage: git remote set-url [--push] <name> <newurl> [<oldurl>]
272272
or: git remote set-url --add <name> <newurl>
273273
or: git remote set-url --delete <name> <url>
@@ -287,7 +287,7 @@ git push -f origin master # 强制推送
287287
只能拉取 `origin` 里的一个url地址,这个fetch-url
288288
默认为你添加的到 `origin`的第一个地址
289289

290-
```shell
290+
```bash
291291
git pull origin master
292292
git pull --all # 获取远程所有内容包括tag
293293
git pull origin next:master # 取回origin主机的next分支,与本地的master分支合并
@@ -301,7 +301,7 @@ git merge origin/next
301301
如果远程主机删除了某个分支,默认情况下,git pull 不会在拉取远程分支的时候,删除对应的本地分支。这是为了防止,由于其他人操作了远程主机,导致git pull不知不觉删除了本地分支。
302302
但是,你可以改变这个行为,加上参数 -p 就会在本地删除远程已经删除的分支。
303303

304-
```shell
304+
```bash
305305
$ git pull -p
306306
# 等同于下面的命令
307307
$ git fetch --prune origin
@@ -322,14 +322,14 @@ git remote add origin git@jslite.github.com:JSLite/JSLite.git # 添加远程路
322322

323323
### 撤销远程记录
324324

325-
```shell
325+
```bash
326326
git reset --hard HEAD~1 # 撤销一条记录
327327
git push -f origin HEAD:master # 同步到远程仓库
328328
```
329329

330330
### 放弃本地的文件修改
331331

332-
```shell
332+
```bash
333333
git reset --hard FETCH_HEAD # FETCH_HEAD表示上一次成功git pull之后形成的commit点。然后git pull
334334
```
335335

@@ -370,7 +370,7 @@ git stash && git stash drop
370370

371371
### 回滚到某个commit提交
372372

373-
```shell
373+
```bash
374374
git revert HEAD~1 # 撤销一条记录 会弹出 commit 编辑
375375
git push # 提交回滚
376376
```
@@ -491,7 +491,7 @@ echo node_modules/ >> .gitignore
491491

492492
在同步之前,需要创建一个远程点指向上游仓库(repo).如果你已经派生了一个原始仓库,可以按照如下方法做。
493493

494-
```shell
494+
```bash
495495
$ git remote -v
496496
# List the current remotes (列出当前远程仓库)
497497
# origin https://github.com/user/repo.git (fetch)
@@ -510,7 +510,7 @@ $ git remote -v
510510

511511
同步上游仓库到你的仓库需要执行两步:首先你需要从远程拉去,之后你需要合并你希望的分支到你的本地副本分支。从上游的存储库中提取分支以及各自的提交内容。 `master` 将被存储在本地分支机构 `upstream/master`
512512

513-
```shell
513+
```bash
514514
git fetch upstream
515515
# remote: Counting objects: 75, done.
516516
# remote: Compressing objects: 100% (53/53), done.
@@ -522,14 +522,14 @@ git fetch upstream
522522

523523
检查你的 fork's 本地 `master` 分支
524524
525-
```shell
525+
```bash
526526
git checkout master
527527
# Switched to branch 'master'
528528
```
529529
530530
合并来自 `upstream/master` 的更改到本地 master 分支上。 这使你的前 fork's `master` 分支与上游资源库同步,而不会丢失你本地修改。
531531

532-
```shell
532+
```bash
533533
git merge upstream/master
534534
# Updating a422352..5fdff0f
535535
# Fast-forward
@@ -611,7 +611,7 @@ git pull origin master --allow-unrelated-histories
611611

612612
### 查看某个文件历史
613613

614-
```shell
614+
```bash
615615
git log --pretty=oneline 文件名 # 列出文件的所有改动历史
616616
git show c178bf49 # 某次的改动的修改记录
617617
git log -p c178bf49 # 某次的改动的修改记录
@@ -680,7 +680,7 @@ git push -f origin master # 强制推送文件,缩写 -f(全写--force)
680680

681681
git clone支持多种协议,除了HTTP(s)以外,还支持SSH、Git、本地文件协议等,下面是一些例子。`git clone <版本库的网址> <本地目录名>`
682682

683-
```shell
683+
```bash
684684
$ git clone http[s]://example.com/path/to/repo.git/
685685
$ git clone ssh://example.com/path/to/repo.git/
686686
$ git clone git://example.com/path/to/repo.git/
@@ -700,14 +700,14 @@ git help config # 获取帮助信息
700700

701701
### add
702702

703-
```shell
703+
```bash
704704
git add * # 跟踪新文件
705705
git add -u [path] # 添加[指定路径下]已跟踪文件
706706
```
707707

708708
### rm
709709

710-
```shell
710+
```bash
711711
rm *&git rm * # 移除文件
712712
git rm -f * # 移除文件
713713
git rm --cached * # 取消跟踪
@@ -717,7 +717,7 @@ git log # 查看提交记录
717717

718718
### commit
719719

720-
```shell
720+
```bash
721721
git commit #提交更新
722722
git commit -m 'message' #提交说明
723723
git commit -a #跳过使用暂存区域,把所有已经跟踪过的文件暂存起来一并提交
@@ -730,7 +730,7 @@ git commit -m '概要描述'$'\n\n''1.详细描述'$'\n''2.详细描述' #提交
730730

731731
### reset
732732

733-
```shell
733+
```bash
734734
git reset HEAD * # 取消已经暂存的文件
735735
git reset --mixed HEAD * # 同上
736736
git reset --soft HEAD * # 重置到指定状态,不会修改索引区和工作树
@@ -740,15 +740,15 @@ git reset -- files * # 重置index区文件
740740

741741
### revert
742742

743-
```shell
743+
```bash
744744
git revert HEAD # 撤销前一次操作
745745
git revert HEAD~ # 撤销前前一次操作
746746
git revert commit # 撤销指定操作
747747
```
748748

749749
### checkout
750750

751-
```shell
751+
```bash
752752
git checkout -- file # 取消对文件的修改(从暂存区——覆盖worktree file)
753753
git checkout branch|tag|commit -- file_name # 从仓库取出file覆盖当前分支
754754
git checkout HEAD~1 [文件] # 将会更新 working directory 去匹配某次 commit
@@ -758,7 +758,7 @@ git checkout -b gh-pages 0c304c9 # 这个表示 从当前分支 commit 哈希
758758

759759
### diff
760760

761-
```shell
761+
```bash
762762
git diff file # 查看指定文件的差异
763763
git diff --stat # 查看简单的diff结果
764764
git diff # 比较Worktree和Index之间的差异
@@ -773,7 +773,7 @@ git diff master...test # 你想找出‘master’,‘test’的共有 父分
773773

774774
### stash
775775

776-
```shell
776+
```bash
777777
git stash # 将工作区现场(已跟踪文件)储藏起来,等以后恢复后继续工作。
778778
git stash list # 查看保存的工作现场
779779
git stash apply # 恢复工作现场
@@ -790,14 +790,14 @@ git merge --squash test # 合并压缩,将test上的commit压缩为一条
790790

791791
### cherry-pick
792792

793-
```shell
793+
```bash
794794
git cherry-pick commit # 拣选合并,将commit合并到当前分支
795795
git cherry-pick -n commit # 拣选多个提交,合并完后可以继续拣选下一个提交
796796
```
797797

798798
### rebase
799799

800-
```shell
800+
```bash
801801
git rebase master # 将master分之上超前的提交,变基到当前分支
802802
git rebase --onto master 169a6 # 限制回滚范围,rebase当前分支从169a6以后的提交
803803
git rebase --interactive # 交互模式,修改commit
@@ -810,7 +810,7 @@ git rebase --abort # 取消合并
810810

811811
### 删除
812812

813-
```shell
813+
```bash
814814
git push origin :branchName # 删除远程分支
815815
git push origin --delete new # 删除远程分支new
816816
git branch -d branchName # 删除本地分支,强制删除用-D
@@ -831,7 +831,7 @@ git push -u origin branchName # 提交分支到远程origin主机中
831831

832832
### 分支合并
833833

834-
```shell
834+
```bash
835835
git merge branchName # 合并分支 - 将分支branchName和当前所在分支合并
836836
git merge origin/master # 在本地分支上合并远程分支。
837837
git rebase origin/master # 在本地分支上合并远程分支。
@@ -844,7 +844,7 @@ git merge test # 将test分支合并到当前分支
844844

845845
### 查看
846846

847-
```shell
847+
```bash
848848
git branch # 列出本地分支
849849
git branch -r # 列出远端分支
850850
git branch -a # 列出所有分支
@@ -856,7 +856,7 @@ git remote show origin # 可以查看remote地址,远程分支
856856

857857
### 新建
858858

859-
```shell
859+
```bash
860860
git branch test # 新建test分支
861861
git branch newBrach 3defc69 # 指定哈希3defc69,新建分支名字为newBrach
862862
git checkout -b newBrach origin/master # 取回远程主机的更新以后,在它的基础上创建一个新的分支
@@ -865,22 +865,22 @@ git checkout -b newBrach 3defc69 # 以哈希值3defc69,新建 newBrach 分支
865865

866866
### 连接
867867

868-
```shell
868+
```bash
869869
git branch --set-upstream dev origin/dev # 将本地dev分支与远程dev分支之间建立链接
870870
git branch --set-upstream master origin/next # 手动建立追踪关系
871871
```
872872

873873
### 分支切换
874874

875-
```shell
875+
```bash
876876
git checkout test # 切换到test分支
877877
git checkout -b test # 新建+切换到test分支
878878
git checkout -b test dev # 基于dev新建test分支,并切换
879879
```
880880

881881
## 远端
882882

883-
```shell
883+
```bash
884884
git fetch <远程主机名> <分支名> # fetch取回所有分支(branch)的更新
885885
git fetch origin remotebranch[:localbranch] # 从远端拉去分支[到本地指定分支]
886886
git merge origin/branch # 合并远端上指定分支
@@ -930,7 +930,7 @@ git rm -rf node_modules/
930930

931931
git是一个分布式代码管理工具,所以可以支持多个仓库,在git里,服务器上的仓库在本地称之为remote。个人开发时,多源用的可能不多,但多源其实非常有用。
932932

933-
```shell
933+
```bash
934934
git remote add origin1 git@github.com:yanhaijing/data.js.git
935935
git remote # 显示全部源
936936
git remote -v # 显示全部源+详细信息
@@ -1042,7 +1042,7 @@ git status # 获取当前的状态,非常有用,因为git会提示接下来
10421042
10431043
解决github push错误的办法:
10441044
1045-
```shell
1045+
```bash
10461046
#vim 编辑器打开 当前项目中的config文件
10471047
vim .git/config
10481048

0 commit comments

Comments
 (0)
0