三 、Git常用命令

命令名称作用
git config --global user.name 用户名设置用户签名
git config --global user.email 邮箱设置用户邮箱
git init初始化本地库
git status查看本地库状态
git add 文件名添加到暂存区
git commit -m "日志信息" 文件名提交到本地库
git reflog查看历史记录
git reset --hard 版本号版本穿梭

3.1 设置用户签名

1)基本语法

git config --global user.name 用户名

git config --global user.email 邮箱

2)案例实操

全局范围的签名设置:

Layne@LAPTOP-Layne MINGW64 /d/Git-Space/SH0720 (master)

$ git config --global user.name Layne

Layne@LAPTOP-Layne MINGW64 /d/Git-Space/SH0720 (master)

$ git config --global user.email Layne@atguigu.com

Layne@LAPTOP-Layne MINGW64 /d/Git-Space/SH0720 (master)

$ cat ~/.gitconfig

[user]

name = Layne

email = Layne@atguigu.com

说明:

签名的作用是区分不同操作者身份。用户的签名信息在每一个版本的提交信息中能够看到,以此确认本次提交是谁做的。Git首次安装必须设置一下用户签名,否则无法提交代码。

**※注意:**这里设置用户签名和将来登录GitHub(或其他代码托管中心)的账号没有任何关系。

3.2 初始化本地库

1)基本语法

git init

2)案例实操

Layne@LAPTOP-Layne MINGW64 /d/Git-Space/SH0720

$ git init

Initialized empty Git repository in D:/Git-Space/SH0720/.git/

Layne@LAPTOP-Layne MINGW64 /d/Git-Space/SH0720 (master)

$ ll -a

total 4

drwxr-xr-x 1 Layne 197609 0 11月 25 14:07 ./

drwxr-xr-x 1 Layne 197609 0 11月 25 14:07 ../

drwxr-xr-x 1 Layne 197609 0 11月 25 14:07 .git/ (.git 初始化的效果,生成git)

3)结果查看

 

3.3 查看本地库状态

1)基本语法

git status

2)案例实操

3.3.1 首次查看(工作区没有任何文件)

Layne@LAPTOP-Layne MINGW64 /d/Git-Space/SH0720 (master)

$ git status

On branch master

No commits yet

nothing to commit (create/copy files and use "git add" to track)

3.3.2 新增文件(hello.txt)

Layne@LAPTOP-Layne MINGW64 /d/Git-Space/SH0720 (master)

$ vim hello.txt

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

3.3.3 再次查看(检测到未追踪的文件)

Layne@LAPTOP-Layne MINGW64 /d/Git-Space/SH0720 (master)

$ git status

On branch master

No commits yet

Untracked files:

(use "git add <file>..." to include in what will be committed)

    hello.txt

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

3.4 添加暂存区

3.4.1 将工作区的文件添加到暂存区

1)基本语法

git add 文件名

2)案例实操

Layne@LAPTOP-Layne MINGW64 /d/Git-Space/SH0720 (master)

$ git add hello.txt

warning: LF will be replaced by CRLF in hello.txt.

The file will have its original line endings in your working directory.

3.4.2 查看状态(检测到暂存区有新文件)

Layne@LAPTOP-Layne MINGW64 /d/Git-Space/SH0720 (master)

$ git status

On branch master

No commits yet

Changes to be committed:

(use "git rm --cached <file>..." to unstage)

    new file:   hello.txt

3.5 提交本地库

3.5.1 将暂存区的文件提交到本地库

1)基本语法

git commit -m "日志信息" 文件名

2)案例实操

Layne@LAPTOP-Layne MINGW64 /d/Git-Space/SH0720 (master)

$ git commit -m "my first commit" hello.txt

warning: LF will be replaced by CRLF in hello.txt.

The file will have its original line endings in your working directory.

[master (root-commit) 86366fa] my first commit

1 file changed, 16 insertions(+)

create mode 100644 hello.txt

3.5.2 查看状态(没有文件需要提交)

Layne@LAPTOP-Layne MINGW64 /d/Git-Space/SH0720 (master)

$ git status

On branch master

nothing to commit, working tree clean

3.6 修改文件(hello.txt)

Layne@LAPTOP-Layne MINGW64 /d/Git-Space/SH0720 (master)

$ vim hello.txt

hello git! hello atguigu! 2222222222222

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

3.6.1 查看状态(检测到工作区有文件被修改)

Layne@LAPTOP-Layne MINGW64 /d/Git-Space/SH0720 (master)

$ git status

On branch master

Changes not staged for commit:

(use "git add <file>..." to update what will be committed)

(use "git checkout -- <file>..." to discard changes in working directory)

    modified:   hello.txt

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

3.6.2 将修改的文件再次添加暂存区

Layne@LAPTOP-Layne MINGW64 /d/Git-Space/SH0720 (master)

$ git add hello.txt

warning: LF will be replaced by CRLF in hello.txt.

The file will have its original line endings in your working directory.

3.6.3 查看状态(工作区的修改添加到了暂存区)

Layne@LAPTOP-Layne MINGW64 /d/Git-Space/SH0720 (master)

$ git status

On branch master

Changes to be committed:

(use "git reset HEAD <file>..." to unstage)

    modified:   hello.txt

3.6.4将暂存区的文件提交到本地库

Layne@LAPTOP-Layne MINGW64 /d/Git-Space/SH0720 (master)

$ git commit -m "my second commit" hello.txt

warning: LF will be replaced by CRLF in hello.txt.

The file will have its original line endings in your working directory.

[master (root-commit) 86366fa] my secondcommit

1 file changed, 16 insertions(+)

create mode 100644 hello.txt

3.7 历史版本

3.7.1 查看历史版本

1)基本语法

git reflog 查看版本信息

git log 查看版本详细信息

2)案例实操

Layne@LAPTOP-Layne MINGW64 /d/Git-Space/SH0720 (master)

$ git reflog

087a1a7 (HEAD -> master) HEAD@{0}: commit: my third commit

ca8ded6 HEAD@{1}: commit: my second commit

86366fa HEAD@{2}: commit (initial): my first commit

3.7.2 版本穿梭

1)基本语法

git reset --hard 版本号

2)案例实操

--首先查看当前的历史记录,可以看到当前是在087a1a7这个版本

Layne@LAPTOP-Layne MINGW64 /d/Git-Space/SH0720 (master)

$ git reflog

087a1a7 (HEAD -> master) HEAD@{0}: commit: my third commit

ca8ded6 HEAD@{1}: commit: my second commit

86366fa HEAD@{2}: commit (initial): my first commit

--切换到86366fa版本,也就是我们第一次提交的版本

Layne@LAPTOP-Layne MINGW64 /d/Git-Space/SH0720 (master)

$ git reset --hard 86366fa

HEAD is now at 86366fa my first commit

--切换完毕之后再查看历史记录,当前成功切换到了86366fa版本

Layne@LAPTOP-Layne MINGW64 /d/Git-Space/SH0720 (master)

$** git reflog**

86366fa (HEAD -> master) HEAD@{0}: reset: moving to 86366fa

087a1a7 HEAD@{1}: commit: my third commit

ca8ded6 HEAD@{2}: commit: my second commit

86366fa (HEAD -> master) HEAD@{3}: commit (initial): my first commit

--然后查看文件hello.txt,发现文件内容已经变化

$ cat hello.txt

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Python Git常用命令大全: Git是现代化的版本控制系统,常被用于软件开发,协作和管理。它允许在开发过程中创建和管理不同的版本,跟踪文件的更改,以及支持团队合作。Python则是一种广泛应用于开发Web应用程序以及数据科学和人工智能领域的高级编程语言。在使用Git时,Python的代码可以与Git进行集成。这里是Python Git常用命令的大全: 1. git init:初始化一个新的 Git 仓库。 2. git clone:从现有的 Git 仓库克隆项目,可以是本地仓库或远端仓库。 3. git add:将文件添加到 Git 仓库中。git add . 可以添加所有更改。 4. git commit:将所有已添加的文件提交到本地 Git 仓库中。 5. git status:查看当前工作目录中 Git 仓库的状态。 6. git log:查看提交记录。 7. git push:将本地 Git 仓库的更改推送到远端仓库。 8. git pull:将远端 Git 仓库的更改拉到本地仓库。 9. git branch:创建新的分支。 10. git checkout:切换分支。 11. git merge:将一个分支的更改合并到另一个分支。 12. git revert:撤销一个提交。 13. git rebase:将一个分支的修改合并到当前分支。 14. git config:配置 Git。 15. git remote:管理远端仓库。 这是Python Git常用命令的大部分命令,但这并不是全部。在使用Git和Python时,这些命令应该是最为重要的。无论是在个人项目中还是团队合作中,这些命令会让你更加高效地使用Git,并保护你的代码免遭不可挽回地灾难。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值