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

git 入门

时间:2014-09-25 03:37:28      阅读:329      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   color   io   os   java   ar   

 

important attributes

1)Snapshots, Not Differences

The major difference between Git and any other VCS (Subversion and friends included) is the way Git thinks about its data. Conceptually, most other systems store information as a list of file-based changes. These systems (CVS, Subversion, Perforce, Bazaar, and so on) think of the information they keep as a set of files and the changes made to each file over time, as illustrated in Figure 1-4.

 

bubuko.com,布布扣


Figure 1-4. Other systems tend to store data as changes to a base version of each file.

 

Git doesn’t think of or store its data this way. Instead, Git thinks of its data more like a set of snapshots of a mini filesystem. Every time you commit, or save the state of your project in Git, it basically takes a picture of what all your files look like at that moment and stores a reference to that snapshot. To be efficient, if files have not changed, Git doesn’t store the file again—just a link to the previous identical file it has already stored. Git thinks about its data more like Figure 1-5.

 

bubuko.com,布布扣


Figure 1-5. Git stores data as snapshots of the project over time.

2)Nearly Every Operation Is Local

Most operations in Git only need local files and resources to operate — generally no information is needed from another computer on your network. This also means that there is very little you can’t do if you’re offline or off VPN.  

 

1. download and install

Debian/Ubuntu
$ apt-get install git
Fedora
$ yum install git
Gentoo
$ emerge --ask --verbose dev-vcs/git
Arch Linux
$ pacman -S git
openSUSE
$ zypper install git
FreeBSD
$ cd /usr/ports/devel/git
$ make install
Solaris 11 Express
$ pkg install developer/versioning/git
OpenBSD
$ pkg_add git

 

set your identity

$ git config --global user.name "John Doe"

$ git config --global user.email johndoe@example.com

 

 

2. 新建git仓库

git init

 Initialized empty Git repository in /home/wish/.git/√

 

[root@localhost wish]# cd ./.git
[root@localhost .git]# ls -al
total 52
drwxr-xr-x.  8 root root 4096 Sep 24 10:49 .
drwx------. 35 wish wish 4096 Sep 24 10:46 ..
drwxr-xr-x.  2 root root 4096 Sep 24 10:33 branches
-rw-r--r--.  1 root root   15 Sep 24 10:49 COMMIT_EDITMSG
-rw-r--r--.  1 root root  111 Sep 24 10:42 config
-rw-r--r--.  1 root root   73 Sep 24 10:33 description
-rw-r--r--.  1 root root   23 Sep 24 10:33 HEAD
drwxr-xr-x.  2 root root 4096 Sep 24 10:33 hooks
-rw-r--r--.  1 root root  112 Sep 24 10:49 index
drwxr-xr-x.  2 root root 4096 Sep 24 10:33 info
drwxr-xr-x.  3 root root 4096 Sep 24 10:49 logs
drwxr-xr-x.  7 root root 4096 Sep 24 10:49 objects
drwxr-xr-x.  4 root root 4096 Sep 24 10:33 refs

 

3. clone a exsiting repository 

Execute the following command to create a local repository of clones:git clone / path / to / Repository 

if the warehouse on the remote server, your command will look something like this: git clone username @ host: / path / to / Repository

 

4. 工作流

bubuko.com,布布扣

1)工作目录

2)暂存区

3)head

你的本地仓库由 git 维护的三棵“树”组成。第一个是你的 工作目录,它持有实际文件;第二个是 暂存区(Index),它像个缓存区域,临时保存你的改动;最后是 HEAD,它指向你最后一次提交的结果。

 

5. 添加

 git add filename(把它们添加到暂存区)

git commit -m 实际提交改动,你的改动已经提交到了 HEAD,但是还没到你的远端仓库。

[root@localhost wish]# git commit -m "file committed"
[master (root-commit) 3413ca3] file committed
 Committer: root <root@localhost.localdomain>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:

    git config --global user.name "Your Name"
    git config --global user.email you@example.com

If the identity used for this commit is wrong, you can fix it with:

    git commit --amend --author=Your Name <you@example.com>

 0 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 HelloWorld.java

git push origin master 将这些改动提交到远端仓库

git 入门

标签:des   style   blog   http   color   io   os   java   ar   

原文地址:http://www.cnblogs.com/wishyouhappy/p/3991841.html

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