Git Tutorial 1 - Goto Staging area

This tutorial is actually for myself as some memos. It provides some example and explanation for the most important commands which might be simple but is worth noting down for your long term memory. I am not going to write tons of commands and their appending complex options, but some of examples that could be easy to understand and enough for your daily work at most of time. I hope they can reflect the backbone of Git and expire you to draw your own diagram for this wonderful version control system in your mind.

Long way to go, but step by step. Here we go...

Before we touch Git, I find necessary and important to take a look at the picture below

figure 1.1

This is very clear for you to understand what typical architecture Git is about. That‘s of course very different from any previous version control systems I‘ve ever used such as VSS(Microsoft Visual SourceSafe) and TFS(Microsoft Team Foundation Server).

Please try to make sure you have installed git bash. This is a cool tool in the terminal I am going to play when going through the tutorials.

As the picture below we can see, there are 3 files in all in the folder /g/html5/openoffice  . Trust me there is no more file even start with dot(.)

figure 1.2

That‘s the folder I want to create repository where the files are going to be managed by Git.

Let‘s type the command to create a repository

git init

After running the command, system will create a folder calls .git in the folder where you want to create repository, as shown below

figure 1.3

Since the new folder name starts with a dot(.), you might not see it in the explorer unless you set the Folder Options by checking item ‘Show hidden files, folders, and drives‘. But if you don‘t like to change the setting, it doesn‘t matter. Typing the command ls with option -a could show you all the hidden files and folders if they are over there as I do in the terminal.

I am about to add these 3 files to the Staging Area. Take a look back at the figure 1.1, and guess which command we are about to type. Yes, that‘s command add as the picture shown obviously.

git add --all

or

git add .

Type command status to show the result after running command add

git status

figure 1.4

If you find you‘ve done something wrong by adding more than you need, for example here, list.png is not supposed to be added, you can undo the command add by running command rm

git rm --cached list.png

or even you want to undo all of them you‘ve added to staging are, you can run this

git rm --cached *

figure 1.5

As the picture shows the 3 files have already come out of staging area and back to untracked files.

时间: 2024-10-06 19:39:46

Git Tutorial 1 - Goto Staging area的相关文章

Git Tutorial 2 - Goto Local Repository

In last episode I have added 3 files to Staging area and also explain how to undo your operation. At next I'm going to show you how to commit the 3 files from staging area to local repository. Git provides developers a private copy of the whole repos

Git Tutorial 5 - Branch and Merge

Branch is a very important concept in Git and doing branch is one of the greatest features. It plays like the concept of context when you're working on it. You can have multiple branches in your repo, and in a time you're working in only one of them.

Git Tutorial 7 - File States

File States Overview Every file in your working directory is mainly in one of 2 states: 1. Tracked : All files that were committed to the last snapshot in Git repository are in state Tracked. They can be one of the following states: 1.1 Unmodified : 

Git Tutorial 3 - Scenario Extension - revert

Git tutorial previously, I have committed the 3 files to local repository. Then suddently I was aware of the file list.png was committed by mistake. It would've been left behind and been clean from my working directory after I get other files in loca

学习笔记 2016/1/27 how to use git (2)

how to use git (2) 建仓库添加文件以及commit的过程: 1.进入目标目录 2.git init 初始化仓库 3.git add <filename>  将文件加入staging area 4.git commit 提交commit git commit -m "Commit Message" 之后修改commit过程循环上述过程3.4 Git diff: git diff  比较当前工作目录和staging area git diff --staged

【Git & Repo & Gerrit 】

Repository 使用GIT管理一个项目的时候,就需要一个仓库(repository)用于存放GIT对项目管理所必须要保存的各种文件,使用 git init 命令创建一个新的仓库.GIT会在当前目录下创建一个.git文件夹,用作仓库.然后,当你使用GIT记录每一次代码改动的时候,GIT就会把需要的信息都放到这个文件夹下面. Commit 每当你完成一个改动(change)的时候,就可以commit一下,记录当前项目的情况(snapshot).每一个commit包含如下信息: commit-i

github学习心得

git中重要的概念: 工作目录(working directory):在工作目录中修改文件,修改后的文件状态是modified,新添加的文件是untracked,通过git add命令将文件保存到staging area中: staging area:保存下次即将提交到git repository中文件的snapshot.文件状态是staged,通过git commit命令提交文件到git repository中: git repository:本地仓库.通过git push命令更新远端服务器仓

GitHub使用方法

以下内容都是全英文的,对githu的使用作了详细的介绍.都是比较简单地词汇,阅读后相信你会对github的工作方式,基本操作很了解了.当然,有可能看完后你会跟我一样觉得,还不如git --help命令来得直接. Git is a distributed version control system To initialize a Git repository in current directory, type the following command:    git init The cur

软件工程课程作业分享

我应经将代码分享至GitHub上了,连接地址:https://github.com/Tsir/ClassTest 使用GitHub的心得体会: 初次使用: git中重要的概念: 工作目录(working directory):在工作目录中修改文件,修改后的文件状态是modified,新添加的文件是untracked,通过git add命令将文件保存到staging area中: staging area:保存下次即将提交到git repository中文件的snapshot.文件状态是stage