【Git】使用总结

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/lc250123/article/details/86656022

1. Ubuntu安装

apt-get install git git-doc gitweb git-gui gitk git-email git-svn

2. 使用帮助

    git --version                #查看git的版本信息
    git [commands] --help        #查看命令commands的帮助信息

3. 创建初始版本库

Git 不关心你是从一个完全空白的目录还是由一个装满文件的目录开始的你的版本管理,这两种情况都一样,cd 到该目录,执行如下命令:

    git init

在该目录下,该命令会创建一个隐藏目录,名为 .git。Git 把所有修订信息都放在这唯一的顶层 .git 目录里。隐藏在 .git 内的版本库由 Git 维护。

4. 将文件添加到版本库中

    git add filename

如果有很多文件,使用如下命令把当前目录及子目录中的文件都添加到版本库里。

    git add . 

不过该操作后,Git 只是暂存了这个文件,这是提交前的中间步骤。Git 将 add 和 commit 这两部分开,以避免频繁变化。这和“批处理”有关。


例子:

新建一个文件夹 test_git,并创建一个文件“hello.txt”,执行如下命令:

    $ mkdir test_code
    $ echo "hello" > hello.txt
    $ git init
    $ ls -al

total 16
drwxr-xr-x  3 root root 4096 1月  28 10:14 .
drwxr-xr-x 17 root root 4096 1月  28 10:12 ..
drwxr-xr-x  7 root root 4096 1月  28 10:34 .git
-rw-r--r--  1 root root   10 1月  28 10:14 hello.txt

    $ git status

On branch master

Initial commit

Untracked files:
  (use "git add <file>..." to include in what will be committed)

	hello.txt

    $ git add hello.txt
    $ git status

On branch master

Initial commit

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

	new file:   hello.txt

可见,在执行完 add 操作后,git status 显示了下次提交时候添加到版本库里的新文件。


5. 提交

一条完全限定的 git commit 命令必须提供日志消息和作者。

    $ git commit -m "Initial contents of test"    \
                 --author="L.C    <[email protected]>"

可能会报这样的错误:

*** Please tell me who you are.

Run

  git config --global user.email "[email protected]"
  git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

这是告诉我们需要配置提交作者,按照上面的操作做就行了。也可以使用 GIT_AUTHOR_NAME 和 GIT_AUTHOR_EMAIL 环境变量来告诉 Git 你的姓名和 email 地址。

6.

 

 

 

猜你喜欢

转载自blog.csdn.net/lc250123/article/details/86656022