当前位置: 首页 > 工具软件 > git-lfs-one > 使用案例 >

git基础命令

丌官翰采
2023-12-01
TR@gs333 MINGW64 ~/Desktop
$ mkdir project
TR@gs333 MINGW64 ~/Desktop
$ cd gitproject/
Initialized empty Git repository in C:/Users/TR/Desktop/gitproject/.git/
-- 首次设置仓库级别用户
TR@gs333 MINGW64 ~/Desktop/gitproject (master)
$ git config user.name gs333
TR@gs333 MINGW64 ~/Desktop/gitproject (master)
$ git config user.email 17621775453@163.com
TR@gs333 MINGW64 ~/Desktop/gitproject (master)
-- 查看仓库基本用户
$ cat .git/config
[core]
        repositoryformatversion = 0
        filemode = false
        bare = false
        logallrefupdates = true
        symlinks = false
        ignorecase = true
[user]
        name = gs333
        email = 17621775453@163.com
-- 首次设置系统级别用户
TR@gs333 MINGW64 ~/Desktop/gitproject (master)
$ git config --global user.name Gs333

TR@gs333 MINGW64 ~/Desktop/gitproject (master)
$ git config --global user.email 17621775453@163.com
TR@gs333 MINGW64 /e/project/git (master)
$ git config --list
diff.astextplain.textconv=astextplain
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
http.sslbackend=openssl
http.sslcainfo=D:/software/git/Git/Git/mingw64/ssl/certs/ca-bundle.crt
core.autocrlf=true
core.fscache=true
core.symlinks=false
pull.rebase=false
credential.helper=manager-core
credential.https://dev.azure.com.usehttppath=true
init.defaultbranch=master
user.name=Gs333
user.email=17621775453@163.com
core.repositoryformatversion=0
core.filemode=false
core.bare=false
core.logallrefupdates=true
core.symlinks=false
core.ignorecase=true


-- 初始化git本地仓库
TR@gs333 MINGW64 /e/project/apitest
$ git init
Initialized empty Git repository in E:/project/apitest/.git/
-- 此处需要把代码放进这个文件夹里,再去add添加暂存区,否则如下报错
TR@gs333 MINGW64 /e/project/apitest (master)
$ git add git01.txt
fatal: pathspec 'git01.txt' did not match any files
-- 正常情况add添加暂存区
TR@gs333 MINGW64 /e/project/apitest (master)
$ git add git01.txt

-- 把代码放到暂存区后可以查看暂存区状态,注:可以用提示命令清空缓存区git rm --cached <file>
TR@gs333 MINGW64 /e/project/apitest (master)
$ git status
On branch master

No commits yet

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

-- 把代码从暂存区提交到git仓库上
TR@gs333 MINGW64 /e/project/apitest (master)
$ git commit -m 'git版本提交代码的日志备注'
[master (root-commit) 085da94] git版本提交代码的日志备注
 1 file changed, 1 insertion(+)
 create mode 100644 git01.txt
-- 把代码从暂存区撤销
TR@gs333 MINGW64 /e/project/apitest (master)
$ git reset HEAD
-- 再次查看暂存区
TR@gs333 MINGW64 /e/project/apitest (master)
$ git status
On branch master
Untracked files:
  (use "git add <file>..." to include in what will be committed)
        git02.txt

nothing added to commit but untracked files present (use "git add" to track)
-- 工作区与git仓库对比
TR@gs333 MINGW64 /e/project/apitest (master)
$ git diff HEAD -- git01.txt
diff --git a/git01.txt b/git01.txt
index ac0e148..2bc503a 100644
--- a/git01.txt
+++ b/git01.txt
@@ -1 +1,5 @@
-git提交
\ No newline at end of file
+git提交
+第二次提交
+变动第三行
+4
+5
\ No newline at end of file


---表示工作区文件 +++是git仓库
-1仓库文件一与+1git仓库文件一的第1行开始连续变动了5行


-- git提交日志(常用)
TR@gs333 MINGW64 /e/project/apitest (master)
$ git log
commit 085da94f78b68f4d1046018887acb1410e871b8f (HEAD -> master)
Author: Gs333 <17621775453@163.com>
Date:   Thu Feb 17 14:36:04 2022 +0800

    git版本提交代码的日志备注
-- 日志简化版
TR@gs333 MINGW64 /e/project/apitest (master)
$ git log -1 --pretty=oneline
085da94f78b68f4d1046018887acb1410e871b8f (HEAD -> master) git版本提交代码的日志
备注
-- 针对回退之后又想恢复到指定版本,但日志没有的情况
TR@gs333 MINGW64 /e/project/apitest (master)
$ git reflog
085da94 (HEAD -> master) HEAD@{0}: reset: moving to HEAD
085da94 (HEAD -> master) HEAD@{1}: commit (initial): git版本提交代码的日志备注

--拉取代码
TR@gs333 MINGW64 /e/project/apitest (master)
$ git checkout -- git01.txt

--删除工作区和git仓库某文件
TR@gs333 MINGW64 /e/project/apitest (master)
$ git rm git01.txt
rm 'git01.txt'

--查看git仓库文件
TR@gs333 MINGW64 /e/project/apitest (master)
$ git ls-files
git02.txt




1.初始化:        git inti

2. 签名(区分开发人员身份):(首次需要)

        仓库级别:        git config 

        系统级别:        git config --global

3.工作区——暂存区——git仓库

git add git01.txt——git commit -m 'git版本提交代码的日志备注

4.撤销暂存区

git reset HEAD

5.查看暂存区

git status

6.工作区与git仓库代码内容对比

git diff HEAD

--- +++  +1,5 

---表示工作区文件 +++是git仓库
-1仓库文件一与+1git仓库文件一的第1行开始连续变动了5行

7.版本回退(回退1个)

git reset --hard HEAD~1

8.版本回复到置顶某个

git reset --hard  085da

(版本标识

TR@gs333 MINGW64 /e/project/apitest (master)
$ git log -1 --pretty=oneline
085da94f78b68f4d1046018887acb1410e871b8f (HEAD -> master) git版本提交代码的日志
备注)

!!如果找不到对应标识,又想恢复,查看总日志

TR@gs333 MINGW64 /e/project/apitest (master)
$ git reflog
085da94 (HEAD -> master) HEAD@{0}: reset: moving to HEAD
085da94 (HEAD -> master) HEAD@{1}: commit (initial): git版本提交代码的日志备注

10.从git仓库拉取

git checkout -- git01.txt

11.删除git仓库和工作区文件

git rm git01.txt

简单点就装小乌龟。

 类似资料: