git 的常用命令

https://www.runoob.com/git/git-basic-operations.html

 

gitee码云的 简易的命令行入门教程:

 

Git 全局设置:

 

git config --global user.name "Andrew0756"
git config --global user.email "5245427+andrew_0756@user.noreply.gitee.com"

 

创建 git 仓库:

 

mkdir travel-qunarnet-t
cd travel-qunarnet-t
git init 
touch README.md
git add README.md
git commit -m "first commit"
#仓库的地址 git remote add origin https://gitee.com/andrew_0756/travel-qunarnet-t.git git push -u origin "master"

 

已有仓库?

 

cd existing_git_repo
#仓库地址 git remote add origin https://gitee.com/andrew_0756/travel-qunarnet-t.git git push -u origin "master"

 

 

git rm 将文件从暂存区和工作区中删除。  注意,是连工作区都删除了。

git add 添加文件到暂存区

 

-----------------------------------------------------------------------

 

git status  查看仓库当前的状态,显示有变更的文件。: 有已经commit 的有哪些   与数据源'origin/main 差几个版本   git add的情况

然后可以根据列出来的提示清除暂存区: use "git restore <file>..." to discard changes in working directory  

git restore . 暂存区全部清除

 

 

git commit -m ''  提交暂存区到本地仓库

 git config -l 查看配置

$ git config --global user.name "runoob"
$ git config --global user.email test@runoob.com

git reset HEAD^ # 回退所有内容到上一个版本  

git reset HEAD^ hello.php # 回退 hello.php 文件的版本到上一个版本 

1.首先查找版本号:git log
2.确定恢复到指定版本:git reset --hard f5c706a6,f5c706a6为版本号

 

强制将本地代码同步到远程仓库:git push origin master --force,master主分支

 

创建分支命令:git branch (branchname) git checkout -b (branchname) 命令来创建新分支并立即切换到该分支下

切换分支命令:git checkout (branchname)  

删除分支: git branch -d (branchname)

$ git branch testing
$ git branch
* master
  testing

现在我们可以看到,有了一个新分支 testing

当你以此方式在上次提交更新之后创建了新分支,如果后来又有更新提交, 然后又切换到了 testing 分支,Git 将还原你的工作目录到你创建分支时候的样子。

 

 

合并分支命令:git merg

 

没有参数时,git branch 会列出你在本地的分支。

$ git branch
* master

在我们第一次提交git的时候:加了参数-u后,以后即可直接用git push代替git push origin master

 

提交到 Github
$ git remote add origin git@github.com:tianqixin/runoob-git-test.git
$ git push -u origin main

要查看当前配置有哪些远程仓库,可以用命令:

$ git remote -v
origin    git@github.com:tianqixin/runoob-git-test.git (fetch)
origin    git@github.com:tianqixin/runoob-git-test.git (push)

实例


更新操作:


$ git pull
$ git pull origin

将远程主机 origin 的 master 分支拉取过来,与本地的 brantest 分支合并。


git pull origin master:brantest

如果远程分支是与当前分支合并,则冒号后面的部分可以省略。


git pull origin master

注意: 1 拉下来更新的时候: 必须先保证已经 git add . git commit -m 'xxx' ,可以不用git push. 然后再git pull
2 即使有冲突,vsc 也会进行冲突选择,去选择哪个留下来
 
 








posted @   Kevin0is0me  阅读(30)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
点击右上角即可分享
微信分享提示