Git 使用以及常用命令

1. Git 常用命令

192:Desktop futantan$ git config --global user.name dandan_claire

192:Desktop futantan$ git config --global user.email 291990515@qq.com

192:Downloads futantan$ cd git-demo/

git add 文件名 (到暂存区)

192:git-demo futantan$ git init 
###初始化git
Initialized empty Git repository in /Users/futantan/Downloads/git-demo/.git/

192:git-demo futantan$ ls -a

. .. .git

192:git-demo futantan$ touch hello.txt
###在git 文件下创建一个文件试试看
192:git-demo futantan$ vim hello.txt 

192:git-demo futantan$ tail -n 2 hello.txt 

im fine too
192:git-demo futantan$ tail -n 1 hello.txt 
192:git-demo futantan$ 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)
192:git-demo futantan$ git add hello.txt 
192:git-demo futantan$ git status 
On branch master
No commits yet
Changes to be committed:

  (use "git rm --cached <file>..." to unstage)
new file:   hello.txt
192:git-demo futantan$ git --version
git version 2.20.1 (Apple Git-117)
192:git-demo futantan$

时这个hello.txt 在暂存区了

下面的命令就是把文件从暂存区删除,但是文件还存在于工作区

192:git-demo futantan$ git rm --cached hello.txt 

rm 'hello.txt'

192:git-demo futantan$ 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)

192:git-demo futantan$ ls

hello.txt

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

基本语法,git commit -m "日志信息" 文件名

提交后用git log 或者git reflog

 修改文件(hello.txt)(以下红色的hello.txt 说明文件hello.txt还没有添加到暂存区)

 git add hello.txt

 git commit -m "xxxx" hello.txt

然后就可以查到两个版本了

 git reset --hard xxx (commit id) 可以回退到你想的commit 版本上来

 

posted @ 2024-03-02 13:09  正霜霜儿  阅读(3)  评论(0编辑  收藏  举报