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 repository which is local repository. Users can perform many operations to theire own local repositories without worring about making dirty of the common space which is remote repository I‘ll mention later on.

figure 2.1

Take a look at the above diagram again. I like this diagram, it‘s easily explained the sequence of how to get and set your files to and from the version control system. It looks like a sequence diagram (a kind of UML), not only because they both have boxes across the top of diagrams but also most importantly they are both used to model usage scenarios. Although the boxes it represents are not actors or instances of classes as well as sequence diagram does, you won‘t be any puzzled to understand these operations are done by youself, a user who type command to move files from a box to another.

See the status of files as below screen‘s shown, I‘ve added 3 files to Staging Area. Next I want to move them to local repository.

figure 2.2

The move from Staging Area to Local Repository is called ‘commit‘. Run the following command

git commit -m "I want the 3 files in local repository"

option -m here indicates there is following message user types to explain this commitment. You‘d better write something, what you‘re doing here, to leave any tips for yourself otherwise time will make you being a stranger to yourself much easily. After your committment, the status will look as below

figure 2.3

Now these files have been gone into local repository.

use ls-tree command to take a look

git ls-tree --full-tree HEAD

the result as shown below

figure 2.4

No doubts they are existing there (HEAD is pointing to local repository).

Seems the episode is done. But git is not one-way stree, it always allows us undo something.

What about get the file or directory back from local repository? When do I want to do this? It‘s probably a reasonable scenario that you‘re not well aware of your commitment included the compile output folder typical named ‘bin‘, and which is commonly discovered by your teammate after you‘ve pushed your managed files and directories from local repository to remote repository.

What can you do to release your buddy? Here we take file list.png as example: list.png is the file I would‘ve not commit to local repository.

Run the command git rm to delete list.png, and then commit the deletion.

git rm list.pnggit commit -m "Remove list.png"

You can see the operation of deletion for list.png is added to staging area. And you can see the file list.png is no longer there by using ls-tree command to check local repo after you commit the deletion you did. See below

Actually the list.png is still here, in local repository, existing in an elder snapshot. But for the latest snapshot and others coming up it is not existing unless you add it and commit it again.

时间: 2024-10-05 18:39:54

Git Tutorial 2 - Goto Local Repository的相关文章

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

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

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.

How to include custom library into maven local repository?--转

原文地址:https://www.mkyong.com/maven/how-to-include-library-manully-into-maven-local-repository/ There are 2 cases that you need to issue Maven’s command to include a jar into the Maven local repository manually. The jar you want to use doesn’t exist in

将jar文件加到Maven的local repository中

对于Maven项目来说,日常使用的多数第三方java库文件都可以从Maven的Central Repository中自动下载,但是如果我们需要的jar文件不在Central Repository中,那么我们就需要手动将自己下载的jar文件加入到Maven的local reposotory中了,此时我们需要向Maven提供用于识别jar文件(可能多个)的groupId, artifactId和version等信息. 我并不打算讲怎么将一个下载的jar库加入到local repository中,我们

Maven依赖中类似was cached in the local repository样的错误

我们在使用maven编译一个项目时经常会遇到诸如此类的问题. Could not get the value for parameter encoding for plugin execution default-resources Plugin org.apache.maven.plugins:maven-resources-plugin:2.6 or one of its dependencies could not be resolved: Failure to find org.code

puppet 详细使用(2)module模块配置ubuntu local repository

1).get puppet module to install apt-cacher-ng puppet module install markhellewell-aptcacherng then,edit nodes.pp and put the 'aptcacherng' class into the repo node class {'aptcacherng':} 2).apply to all clientscreate a manifest file including these c

如何设置maven的local repository目录

step1:默认会放在~/.m2/repository目录下 (“~”代表用户的目录,比如windows下一般都是C:\Documents and Settings\[你的用户名]\.由于“Documents and Settings”中含有“空格”会导致“Illegal character in path”异常) 安装Maven后我们会在用户目录下发现.m2 文件夹.默认情况下,该文件夹下放置了Maven本地仓库.m2/repository.所有的Maven构件(artifact)都被存储到该

Failure to transfer org.apache.maven:maven-archiver:pom:2.5 from http://repo.maven.apache.org/ maven2 was cached in the local repository, resolution will not be reattempted until the update interv

Failure to transfer org.apache.maven:maven-archiver:pom:2.5 from http://repo.maven.apache.org/ maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced. Origi