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 @   正霜霜儿  阅读(5)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
点击右上角即可分享
微信分享提示