当前位置:   article > 正文

git 与github 命令行操作与控制_fatal: unrecognized argument: --abbrev-commmit

fatal: unrecognized argument: --abbrev-commmit

一、git
1.download下载
https://www.git-scm.com/
2.配置 用户名和邮箱
假设用户名为"xxxx",邮箱为"xxxx@xxxx.com"

User@DESKTOP-01EST3R MINGW64 ~
$ git config --global user.name "xxxx"

User@DESKTOP-01EST3R MINGW64 ~
$ git config --global user.email "xxxx@xxxx.com"

User@DESKTOP-01EST3R MINGW64 ~
$
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

3.更改目录

$ cd /d/ml_tech_src


User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src
$ pwd
/d/ml_tech_src

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src
$
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

4.编辑hello.py的python文件

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1
$ vim hello.py

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1
$ ls
hello.py

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1
$ python hello.py

hello,world
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

5.初始化仓库

$ git init
Reinitialized existing Git repository in D:/ml_tech_src/ml_1/.git/
  • 1
  • 2

6.检查状态

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)
$ git status
On branch master

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        hello.py

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

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)
$
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

7.文件加入仓库

$ git add .
warning: LF will be replaced by CRLF in hello.py.
The file will have its original line endings in your working directory

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)
$ git status
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
        new file:   hello.py


User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

8.提交

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)
$ git commit -m "my first committing"
[master (root-commit) ef7cc70] my first committing
 1 file changed, 1 insertion(+)
 create mode 100644 hello.py

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)
$ git status
On branch master
nothing to commit, working tree clean

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)
$
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

9.查看提交历史

$ git log
commit ef7cc70308420d56726e8102caeecb4715319511 (HEAD -> master)
Author: spx <lx@myhaspl.com>
Date:   Tue Nov 30 09:44:12 2021 +0800

    my first committing

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

10.修改源文件

$ cat hello.py
print("hello,world")
print("ok")

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)
$ git status
On branch master
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:   hello.py

no changes added to commit (use "git add" and/or "git commit -a")

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)
$
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

11.第2次提交

$ git commit -am "commit again"
warning: LF will be replaced by CRLF in hello.py.
The file will have its original line endings in your working directory
[master da643c7] commit again
 1 file changed, 1 insertion(+)

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)
$ git status
On branch master
nothing to commit, working tree clean

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)
$
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  1. 增加文件,修改文件并提交
$ vim hello2.py

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)
$ python hello2.py
hi

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)
$ ls
hello.py  hello2.py

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)
$ git status
On branch master
Untracked files:
  (use "git add <file>..." to include in what will be committed)
        hello2.py

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

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)
$
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
$ vim hello.py

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)
$ cat hello.py
print("hello,world")
print("ok")
print("!!!!!")

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)
$ python hello.py
hello,world
ok
!!!!!

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)
$ git status
On branch master
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:   hello.py

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        hello2.py

no changes added to commit (use "git add" and/or "git commit -a")

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)
$
  • 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

-a 表示所有修改的文件全部提交

$ git add .
warning: LF will be replaced by CRLF in hello.py.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in hello2.py.
The file will have its original line endings in your working directory


User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)
$ git commit -am "my commit!"
[master ccf29ef] my commit!
 2 files changed, 2 insertions(+)
 create mode 100644 hello2.py

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)
$ git status
On branch master
nothing to commit, working tree clean

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)
$
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

13.撤销修改

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)
$ cat hello2.py
print("hi")

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)
$ vim hello2.py

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)
$ cat hello2.py
print("hi")
print("finish!")

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)
$ git status
On branch master
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:   hello2.py

no changes added to commit (use "git add" and/or "git commit -a")

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)
$ git checkout .
Updated 1 path from the index

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)
$ cat hello2.py
print("hi")

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)
$ git status
On branch master
nothing to commit, working tree clean
  • 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

使用checkout . 恢复到上次修改的前一个状态。
14.恢复到以前的提交

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)
$ git log --prety=oneline
fatal: unrecognized argument: --prety=oneline

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)
$ git log --pretty=oneline
ccf29effa7c589014e488c4da2c8acc64f78632e (HEAD -> master) my commit!
da643c7548b6e8fe1b9d5d23f36d38d3f522246c commit again
ef7cc70308420d56726e8102caeecb4715319511 my first committing

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)
$ git checkout da643c
Note: switching to 'da643c'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at da643c7 commit again

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 ((da643c7...))
$ ls
hello.py

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 ((da643c7...))


User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 ((da643c7...))
$ cat hello.py
print("hello,world")
print("ok")

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 ((da643c7...))
$ git status
HEAD detached at da643c7
nothing to commit, working tree clean
  • 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

恢复到以前的状态,将离开分支master,进行头指针分离。
可回到master分支。

$ git checkout master
Previous HEAD position was da643c7 commit again
Switched to branch 'master'

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)
$ git status
On branch master
nothing to commit, working tree clean

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)
$ ls
hello.py  hello2.py

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)
$ git log --pretty=oneline
ccf29effa7c589014e488c4da2c8acc64f78632e (HEAD -> master) my commit!
da643c7548b6e8fe1b9d5d23f36d38d3f522246c commit again
ef7cc70308420d56726e8102caeecb4715319511 my first committing

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)
$ cat hello.py
print("hello,world")
print("ok")
print("!!!!!")
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24

15.master强制恢复到以前的指定状态

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)
$ cat hello.py
print("hello,world")
print("ok")
print("!!!!!")

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)
$ git reset --hard da643c
HEAD is now at da643c7 commit again

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)
$ ls
hello.py

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)
$ cat hello.py
print("hello,world")
print("ok")

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)
$ git status
On branch master
nothing to commit, working tree clean

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)
$ git log --pretty=oneline
da643c7548b6e8fe1b9d5d23f36d38d3f522246c (HEAD -> master) commit again
ef7cc70308420d56726e8102caeecb4715319511 my first committing

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)
$
  • 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

使用git reset --hard da643c完成
16.删除一个仓库

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)
$ git status
On branch master
nothing to commit, working tree clean

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)
$ rm -rf .git

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1
$ git status
fatal: not a git repository (or any of the parent directories): .git
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

17.重新建立仓库

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1
$ git init
Initialized empty Git repository in D:/ml_tech_src/ml_1/.git/

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)
$ git status
On branch master

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        hello.py

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

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)
$
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)
$ git add .

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)
$ git commit -m "restart commiting"
[master (root-commit) afb0cf7] restart commiting
 1 file changed, 2 insertions(+)
 create mode 100644 hello.py

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)
$ git status
On branch master
nothing to commit, working tree clean

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

二、github

1.登录设置

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1
$ git config --global user.name "spxai"
  • 1
  • 2

确认正确设置了 Git 用户名:

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1
$ git config --global user.name
spxai

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1
$ git config --global user.email "msp@myhaspl.com"

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1
$ git config --global user.email
msp@myhaspl.com
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

2.远程仓库创建
例如:

要新增远程,请在终端上存储仓库的目录中使用 git remote add 命令。

git remote add 命令使用两个参数:

远程命令,如 origin
远程 URL,如 https://github.com/user/repo.git
例如:

$ git remote add origin https://github.com/user/repo.git
# Set a new remote

$ git remote -v
# Verify new remote
> origin  https://github.com/user/repo.git (fetch)
> origin  https://github.com/user/repo.git (push)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
$ git init -b master
Initialized empty Git repository in D:/ml_tech_src/ml_1/.git/

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)
$ git status
On branch master

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        hello.py

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

$ ls
hello.py

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)
$ git remote add ml_1 https://github.com/user/repo.git

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)
$ git status
On branch master

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        hello.py

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

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)


$ git remote -v
ml_1    https://github.com/user/repo.git (fetch)
ml_1    https://github.com/user/repo.git (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

3.提交仓库

(1)相关基础

更改远程仓库的 URL

git remote set-url 命令使用两个参数:

现有远程仓库的名称。 例如,源仓库或上游仓库是两种常见选择。
远程仓库的新 URL。 例如:

如果您要更新为使用 HTTPS,您的 URL 可能如下所示:
https://github.com/USERNAME/REPOSITORY.git
如果您要更新为使用 SSH,您的 URL 可能如下所示:
git@github.com:USERNAME/REPOSITORY.git
  • 1
  • 2
  • 3
  • 4
$ git remote set-url ml_1 https://github.com/spxai/repo.git

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)
$ git remote -v
ml_1    https://github.com/spxai/repo.git (fetch)
ml_1    https://github.com/spxai/repo.git (push)

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

另外,还可以重命名远程仓库
使用 git remote rename 命令可重命名现有的远程。

git remote rename 命令使用两个参数:

现有的远程名称,例如 origin
远程的新名称,例如 destination
例如:

$ git remote -v
# 查看现有远程
> origin  https://github.com/OWNER/REPOSITORY.git (fetch)
> origin  https://github.com/OWNER/REPOSITORY.git (push)

$ git remote rename origin destination
# 将远程名称从 'origin' 更改为 'destination'

$ git remote -v
# 验证远程的新名称
> destination  https://github.com/OWNER/REPOSITORY.git (fetch)
> destination  https://github.com/OWNER/REPOSITORY.git (push)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
$ git remote -v
ml_1    https://github.com/spxai/repo.git (fetch)
ml_1    https://github.com/spxai/repo.git (push)

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)
$ git remote rename ml_1 ml-1

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)
$ git remote -v
ml-1    https://github.com/spxai/repo.git (fetch)
ml-1    https://github.com/spxai/repo.git (push)

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)
$
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

https:// 克隆 URL 在所有仓库中提供,与可见性无关。 即使您在防火墙或代理后面,https:// 克隆 URL 也有效。

当您在命令行中使用 HTTPS URL 对远程仓库执行 git clone、git fetch、git pull 或 git push 命令时,Git 将要求您输入 GitHub 用户名和密码。

$ git commit -m "First commit"
[master (root-commit) 69cdcab] First commit
 1 file changed, 2 insertions(+)
 create mode 100644 hello.py

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (master)

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

推送提交到远程仓库
使用 git push 将本地分支上的提交推送到远程仓库。

git push 命令使用两个参数:

远程命令,如 origin
分支名称,如 main
例如:

git push
例如,您通常运行 git push origin main 来推送本地更改到在线仓库。

重命名分支
要重命名分支,同样使用 git push 命令,但要加上一个或多个参数:新分支的名称。
例如:

git push :
这会将 LOCALBRANCHNAME 推送到 REMOTENAME,但其名称将改为 REMOTEBRANCHNAME。

推送标记
默认情况下,没有其他参数时,git push 会发送所有名称与远程分支相同的匹配分支。

要推送单一标记,可以发出与推送分支相同的命令:

git push
要推送所有标记,可以输入命令:

git push --tags
删除远程分支或标记
删除分支的语法初看有点神秘:

git push :
请注意,冒号前有一个空格。 命令与重命名分支的步骤类似。 但这里是告诉 Git 不要推送任何内容到 REMOTENAME 上的 BRANCHNAME。 因此,git push 会删除远程仓库上的分支。

远程和复刻
您可能已经知道,您可以对 GitHub 上的仓库“复刻”。

在克隆您拥有的仓库时,向其提供远程 URL,告知 Git 到何处提取和推送更新。 如果要协作处理原始仓库,可添加新的远程 URL(通常称为 upstream)到本地 Git 克隆:

git remote add upstream <THEIR_REMOTE_URL>
现在可以从其复刻提取更新和分支:

git fetch upstream
# Grab the upstream remote's branches
> remote: Counting objects: 75, done.
> remote: Compressing objects: 100% (53/53), done.
> remote: Total 62 (delta 27), reused 44 (delta 9)
> Unpacking objects: 100% (62/62), done.
> From https://github.com/octocat/repo
>  * [new branch]      main     -> upstream/main
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

克隆仓库
要获取其他用户仓库的完整副本,请使用 git clone,如下所示:

$ git clone https://github.com/USERNAME/REPOSITORY.git
# 将仓库克隆到您的计算机
  • 1
  • 2

运行 git clone 时,将发生以下操作:
创建名为 repo 的文件夹
将它初始化为 Git 仓库
创建名为 origin 的远程仓库,指向用于克隆的 URL
将所有的仓库文件和提交下载到那里
默认分支已检出

从远程仓库获取更改
使用 git fetch 可检索其他人完成的新工作。 从仓库获取将会获取所有新的远程跟踪分支和标记,但不会将这些更改合并到您自己的分支中。

如果已经有一个本地仓库包含为所需项目设置的远程 URL,您可以在终端使用 git fetch remotename 获取所有新信息:

$ git fetch remotename
# 获取远程仓库的更新
  • 1
  • 2

合并更改到本地分支
合并可将您的本地更改与其他人所做的更改组合起来。

通常将远程跟踪分支(即从远程仓库获取的分支)与您的本地分支进行合并:

$ git merge remotename/branchname
# 将在线更新与您的本地工作进行合并
  • 1
  • 2

从远程仓库拉取更改
git pull 是在同一个命令中完成 git fetch 和 git merge 的便捷方式。

$ git pull remotename branchname
# 获取在线更新并将其与您的本地工作进行合并
  • 1
  • 2

(2)提交操作



github页面中创建ml_1项目
或使用[GitHub CLI  https://github.com/cli/cli#installation](https://github.com/cli/cli#installation)


```bash
User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (main)
$ rm -rf .git

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1
$ git init -b main
Initialized empty Git repository in D:/ml_tech_src/ml_1/.git/

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (main)

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (main)
$ git add .

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (main)
$ git commit -m "first commit"
[main (root-commit) 140da5c] first commit
 1 file changed, 2 insertions(+)
 create mode 100644 hello.py

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (main)
$ git status
On branch main
nothing to commit, working tree clean

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (main)
$ git remote add ml_1 https://github.com/spxai/ml_1.git

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (main)
$ git remote -v
ml_1    https://github.com/spxai/ml_1.git (fetch)
ml_1    https://github.com/spxai/ml_1.git (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

使用 git fetch 可检索其他人完成的新工作。 从仓库获取将会获取所有新的远程跟踪分支和标记,但不会将这些更改合并到您自己的分支中。

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (main)
$ git fetch ml_1 main
From https://github.com/spxai/ml_1
 * branch            main       -> FETCH_HEAD
  • 1
  • 2
  • 3
  • 4

git merge合并更改到本地分支
将远程跟踪分支(即从远程仓库获取的分支)与您的本地分支进行合并

$ git merge ml_1/main --allow-unrelated-histories
Merge made by the 'ort' strategy.
 .gitignore | 129 ++++++++++++++++
 LICENSE    | 504 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 633 insertions(+)
 create mode 100644 .gitignore
 create mode 100644 LICENSE

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (main)
$
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
$ ls -la
total 37
drwxr-xr-x 1 User 197121     0 Nov 30 16:23 ./
drwxr-xr-x 1 User 197121     0 Nov 29 19:04 ../
drwxr-xr-x 1 User 197121     0 Nov 30 16:24 .git/
-rw-r--r-- 1 User 197121  1928 Nov 30 16:23 .gitignore
-rw-r--r-- 1 User 197121 27030 Nov 30 16:23 LICENSE
-rw-r--r-- 1 User 197121    35 Nov 30 11:11 hello.py

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (main)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

提交更新

$ git push ml_1 main
Enumerating objects: 6, done.
Counting objects: 100% (6/6), done.
Delta compression using up to 4 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (5/5), 545 bytes | 109.00 KiB/s, done.
Total 5 (delta 0), reused 0 (delta 0), pack-reused 0
To https://github.com/spxai/ml_1.git
   2d3145d..0c10459  main -> main

User@DESKTOP-01EST3R MINGW64 /d/ml_tech_src/ml_1 (main)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/466929?site
推荐阅读
相关标签
  

闽ICP备14008679号