Git Quick Start

本文介绍Git的基本使用方法,包括创建和提交文件、克隆仓库及创建补丁等操作。此外还详细讲解了Git的工作流程,从修改工作目录文件到将文件快照永久存储至Git目录的全过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Git is...

Git is a free & open source, distributed version control system designed to handle everything from small to very large projects with speed and efficiency.

Every Git clone is a full-fledged repository with complete history and full revision tracking capabilities, not dependent on network access or a central server.Branching and merging are fast and easy to do.

Git is used for version control of files, much like tools such as Mercurial, Bazaar, Subversion, CVS, Perforce, and Team Foundation Server.


Creating and Commiting

$ cd (project-directory)
$ git init
$ (add some files)
$ git add .
$ git commit -m 'Initial commit'


Cloning and Creating a Patch

$ git clone git://github.com/git/hello-world.git
$ cd hello-world
$ (edit files)
$ git add (files)
$ git commit -m 'Explain what I changed'
$ git format-patch origin/master


Basic Commands

$ git status
$ git log


The basic Git workflow goes something like this:

1. You modify files in your working directory.
2. You stage the files, adding snapshots of them to your staging area.
3. You do a commit, which takes the files as they are in the staging area and stores that snapshot permanently to your Git directory.













Set Up SSH Keys

~$ cd .ssh
/home/bambreeze/.ssh
.ssh$ ll
total 4.0K
-rw-r--r-- 1 bambreeze bambreeze 1.3K 2011-08-09 21:55 known_hosts
.ssh$ ssh-keygen -t rsa -C "bambreeze@gmail.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/home/bambreeze/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/bambreeze/.ssh/id_rsa.
Your public key has been saved in /home/bambreeze/.ssh/id_rsa.pub.
The key fingerprint is:
...
The key's randomart image is:
...
.ssh$ ls
id_rsa  id_rsa.pub  known_hosts
.ssh$ vim id_rsa.pub
.ssh$ ssh -T git@github.com
Hi bambreeze! You've successfully authenticated, but GitHub does not provide shell access.


Create A Repository @ GitHub

ldd3$ pwd
/home/bambreeze/workspace/git-space/ldd3
ldd3$ ll
...
ldd3$ git init
Initialized empty Git repository in /home/bambreeze/workspace/git-space/ldd3/.git/
ldd3$ git add .
ldd3$ git status
...
ldd3$ git commit -m "initial commit for Linux Device Driver (3rd) examples"
Created initial commit ec142ce: initial commit for Linux Device Driver (3rd) examples
 99 files changed, 13387 insertions(+), 0 deletions(-)
...
ldd3$ git status
# On branch master
nothing to commit (working directory clean)
ldd3$ touch README
ldd3$ vim README
ldd3$ git add README
ldd3$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       new file:   README
#
ldd3$ git commit -m "adding README file for LDD3-Examples project"
Created commit 40db767: adding README file for LDD3-Examples project
 1 files changed, 2 insertions(+), 0 deletions(-)
 create mode 100644 README
ldd3$ git remote add origin git@github.com:bambreeze/LDD3-Examples.git
ldd3$ git push origin master
Counting objects: 123, done.
Compressing objects: 100% (121/121), done.
Writing objects: 100% (123/123), 100.69 KiB, done.
Total 123 (delta 46), reused 0 (delta 0)
To git@github.com:bambreeze/LDD3-Examples.git
 * [new branch]      master -> master


参考文献

1. http://git-scm.com/

2. http://progit.org/book/

3. https://github.com/

转载于:https://www.cnblogs.com/bambreeze/archive/2011/08/10/2143731.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值