码迷,mamicode.com
首页 > 其他好文 > 详细

Git Tutorial 2 - Goto Local Repository

时间:2015-11-12 19:43:35      阅读:314      评论:0      收藏:0      [点我收藏+]

标签:

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.png
git 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.

Git Tutorial 2 - Goto Local Repository

标签:

原文地址:http://www.cnblogs.com/vjianwang/p/gittutorial2.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!