首页 > 其他分享 >[1092] Git Tutorial

[1092] Git Tutorial

时间:2025-01-15 12:43:38浏览次数:1  
标签:files git 1092 add Git command branch Tutorial

Ref: Git Tutorial - W3School


Using Git with Command Line

git --version
git version 2.30.2.windows.1

Configure Git

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

Creating Git Folder

mkdir myproject
cd myproject

Initialize Git

git init 
Initialized empty Git repository in /Users/user/myproject/.git/

Git Adding New Files

We check the Git status and see if it is a part of our repo:

git status
On branch master

No commits yet

Untracked files:
  (use "git add ..." to include in what will be committed)
    index.html

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

Files in your Git repository folder can be in one of 2 states:

  • Tracked - files that Git knows about and are added to the repository
  • Untracked - files that are in your working directory, but not added to the repository

Git Staging Environment

One of the core functions of Git is the concepts of the Staging Environment, and the Commit.

As you are working, you may be adding, editing and removing files. But whenever you hit a milestone or finish a part of the work, you should add the files to a Staging Environment.

Staged files are files that are ready to be committed to the repository you are working on. You will learn more about commit shortly.

For now, we are done working with index.html. So we can add it to the Staging Environment:

git add index.html

Git Add More than One File

You can also stage more than one file at a time.

Now add all files in the current directory to the Staging Environment:

git add --all
or
git add -A
or
git add .

Using --all instead of individual filenames will stage all changes (new, modified, and deleted) files.

git status
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached ..." to unstage)
        new file:   README.md
        new file:   bluestyle.css
        new file:   index.html

Git Commit

Since we have finished our work, we are ready move from stage to commit for our repo.

git commit -m "First release of Hello World!"
[master (root-commit) 221ec6e] First release of Hello World!
 3 files changed, 26 insertions(+)
 create mode 100644 README.md
 create mode 100644 bluestyle.css
 create mode 100644 index.html

The commit command performs a commit, and the -m "message" adds a message.

The Staging Environment has been committed to our repo, with the message:
"First release of Hello World!"

Git Commit Log

To view the history of commits for a repository, you can use the log command:

git log
commit 09f4acd3f8836b7f6fc44ad9e012f82faf861803 (HEAD -> master)
Author: w3schools-test 
Date:   Fri Mar 26 09:35:54 2021 +0100

    Updated index.html with a new line

commit 221ec6e10aeedbfd02b85264087cd9adc18e4b26
Author: w3schools-test 
Date:   Fri Mar 26 09:13:07 2021 +0100

    First release of Hello World!

Git Help

If you are having trouble remembering commands or options for commands, you can use Git help.

There are a couple of different ways you can use the help command in command line:

  • git command -help -  See all the available options for the specific command
  • git help --all -  See all possible commands

 Let's go over the different commands.


Git -help See Options for a Specific Command

Any time you need some help remembering the specific option for a command, you can use git command -help:

New Git Branch

git branch hello-world-images

Now we created a new branch called "hello-world-images"

Let's confirm that we have created a new branch:

git branch hello-world-images
* master

We can see the new branch with the name "hello-world-images", but the * beside master specifies that we are currently on that branch.

checkout is the command used to check out a branch. Moving us from the current branchto the one specified at the end of the command:

git checkout hello-world-images
Switched to branch 'hello-world-images'

Now we have moved our current workspace from the master branch, to the new branch

Switching Between Branches

git checkout master
Switched to branch 'master'

Merge Branches

git checkout hello-world-images
Switched to branch 'hello-world-images'

 

标签:files,git,1092,add,Git,command,branch,Tutorial
From: https://www.cnblogs.com/alex-bn-lee/p/18672783

相关文章

  • Git使用
    配置查看当前系统的Git配置gitconfig--list设置当前主机的Git的账户名及邮箱地址gitconfig--globaluser.name"YourName"gitconfig--globaluser.email"email@example.com"项目在远程拉取代码gitclonehttps://github.com/liduchang/redis初始化Git项目git......
  • [SNCPC2019] Digit Mode
    前言不管从实现方式到智慧程度都是数位\(\rm{dp}\)好题,写一下思路首先你发现常规的数位\(\rm{dp}\)方法不可以实现原因是不能对于一个数求出其\(m(x)\)容易考虑到逆向思考,你钦定\(m(x)\)的值,看有多少个\(x\)满足此要求怎么做?先考虑最简单的情况,如果从\(......
  • Gitlab搭建npm仓库
    由于图片和格式解析问题,为了更好阅读体验可前往阅读原文:::warning使用gitlab的仓库注册表特性需要版本14.0+,如果你的版本比较低,请先根据自己的需求合理升级后再使用:::npm私有仓库的搭建方式有很多种,比如使用docker(阅读此篇),这里讲述如何使用gitlab作为npm仓库方法,gitlab......
  • git整体使用流程
    一、场景说明本地有文件想在github创建一个远程仓库在本地修改,同时同步到远端二、流程设置用户名和邮箱目的:标识每次提交者的身份设置全局用户名:gitconfig--globaluser.name"YourName"设置全局邮箱:gitconfig--globaluser.email"your.email@example.com"......
  • VS Code 中,GitLens 和 Git Graph
    在VSCode中,GitLens和GitGraph插件是两款非常强大的Git扩展,可以显著增强Git操作的效率和可视化功能。1.安装GitLens和GitGraph插件1.1安装GitLens插件GitLens是一个强大的VSCode扩展,用于增强Git的功能,提供更多的提交历史、作者信息、文件变更......
  • Windows下Git Bash的tar命令使用
    Administrator@WIN-5B2ST4S1K5HMINGW64~/Documents/spark$lsspark-3.5.4-bin-hadoop3.tgzspark-3.5.4-bin-without-hadoop.tgzAdministrator@WIN-5B2ST4S1K5HMINGW64~/Documents/spark$tar-xspark-3.5.4-bin-hadoop3.tgz./tar:Refusingtoreadarchivecon......
  • GitLab 国际站中国大陆等地区停服,如何将数据快速迁移到云效
    代码托管平台GitLab国际站(GitLab.com)近日发布公告,官宣即将停止对中国大陆、香港、澳门地区的用户账号提供服务,并提供60天过渡期自行迁移账户数据,超期未迁移的账号可能会被GitLab清除。这一重要决策引起了全球开发者的广泛关注和讨论。为了承接本次调整受影响地区的用户,GitL......
  • GitLab 国际站中国大陆等地区停服,如何将数据快速迁移到云效
    代码托管平台GitLab国际站(GitLab.com)近日发布公告,官宣即将停止对中国大陆、香港、澳门地区的用户账号提供服务,并提供60天过渡期自行迁移账户数据,超期未迁移的账号可能会被GitLab清除。这一重要决策引起了全球开发者的广泛关注和讨论。为了承接本次调整受影响地区的用户,GitL......
  • github Desktop小白下载与汉化教程
    GitHubDesktop是一款由GitHub官方推出的图形化工具,旨在简化Git和GitHub的使用流程,特别适合不熟悉命令行的用户。它支持仓库的克隆、创建和管理,方便进行分支操作(如创建、切换和合并分支),并提供了直观的界面来提交、撤销和同步更改。此外,GitHubDesktop还能帮助用户创建......
  • Gitlab代码仓库私有化部署
    GitLab是一个强大的代码仓库管理系统,它使用Git作为版本控制工具,并提供了代码托管、CI/CD、问题跟踪和合并请求管理等丰富的功能。对于需要严格控制代码安全和隐私的企业及开发者来说,私有化部署GitLab代码仓库是必要的步骤。下面将介绍如何进行私有化部署。【可选】镜像源配......