Git 基本命令

1、初始化命令:

git init
admin@jimmy MINGW64 /e/Desktop/dbhost
$ git init
Initialized empty Git repository in E:/Desktop/dbhost/.git/


2、检测当前状态命令:

git status

红色:新增/修改
绿色:git已经管理
生成版本

admin@jimmy MINGW64 /e/Desktop/dbhost (master)
$ git status
On branch master

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        leetcode.html
        readme.txt

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

3、添加文件:

git  add {filename}
admin@jimmy MINGW64 /e/Desktop/dbhost (master)
$ git add leetcode.html

admin@jimmy MINGW64 /e/Desktop/dbhost (master)
$ git status
On branch master

No commits yet

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

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


4、添加所有文件:

git add .

admin@jimmy MINGW64 /e/Desktop/dbhost (master)
$ git add .
admin@jimmy MINGW64 /e/Desktop/dbhost (master)
$ git status
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
        new file:   leetcode.html
        new file:   readme.txt



5、提交加描述:

git commit -m '{decription} '
admin@jimmy MINGW64 /e/Desktop/dbhost (master)
$ git commit -m 'v1'
Author identity unknown

*** Please tell me who you are.

Run

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: unable to auto-detect email address (got 'admin@LAPTOP-RO1PQ5JM.(none)')


注意:当创建新项目,git上传提交时出现了如上问题,按照提示操作就可以了。

admin@jimmy MINGW64 /e/Desktop/dbhost (master)
$ git config --global user.email "jimmy@163.com"

admin@jimmy MINGW64 /e/Desktop/dbhost (master)
$ git config --global user.name "jimmy"

admin@jimmy MINGW64 /e/Desktop/dbhost (master)
$ git commit -m 'v1'
[master (root-commit) 76c07ad] v1
 2 files changed, 38 insertions(+)
 create mode 100644 leetcode.html
 create mode 100644 readme.txt

admin@jimmy MINGW64 /e/Desktop/dbhost (master)
$ git status
On branch master
nothing to commit, working tree clean

当文件出现更改后,需要重新提交:

admin@jimmy MINGW64 /e/Desktop/dbhost (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:   readme.txt

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

admin@jimmy MINGW64 /e/Desktop/dbhost (master)
$ git add .

admin@jimmy MINGW64 /e/Desktop/dbhost (master)
$ git status
On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        modified:   readme.txt

admin@jimmy MINGW64 /e/Desktop/dbhost (master)
$ git commit -m 'v2'
[master dbaffde] v2
 1 file changed, 1 insertion(+)


6、查看版本日志:

 git log
admin@jimmy MINGW64 /e/Desktop/dbhost (master)
$ git log
commit dbaffde35dd5eac48c2d505a51350c6bdf656335 (HEAD -> master)
Author: jimmy <jimmy@163.com>
Date:   Sun Apr 7 16:13:50 2024 +0800

    v2

commit 76c07ad88369073ebf330d040a8c747315bafc20
Author: jimmy <jimmy@163.com>
Date:   Sun Apr 7 16:07:54 2024 +0800

    v1


  • 6
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值