Git(2):基本操作
Git 创建仓库
执行<git init>命令后,Git仓库会生成一个.git目录,该目录包含了资源的所有元数据,其他的项目目录保持不变(Git 只在仓库的根目录生成 .git 目录)。
使用当前目录作为Git仓库
$git init
使用指定目录作为Git仓库
$git init <directory>
使用<git clone>从Git仓库中拷贝项目。
克隆仓库
$git clone <remote repository>
克隆到指定的目录
$git clone <remote repository> <local directory>
admin MINGW64 / $ cd c admin MINGW64 /c $ mkdir GitRepositoryTest admin MINGW64 /c $ cd GitRepositoryTest/ admin MINGW64 /c/GitRepositoryTest $ git init test1 Initialized empty Git repository in C:/GitRepositoryTest/test1/.git/ admin MINGW64 /c/GitRepositoryTest $ ls test1/ admin MINGW64 /c/GitRepositoryTest $ git git clone git@github.com:lyz170/DesignPattern.git DesignPattern Cloning into 'DesignPattern'... remote: Counting objects: 7132, done. remote: Compressing objects: 100% (558/558), done. remote: Total 7132 (delta 6541), reused 7065 (delta 6498) Receiving objects: 100% (7132/7132), 1.84 MiB | 0 bytes/s, done. Resolving deltas: 100% (6541/6541), done. Checking connectivity... done. Checking out files: 100% (2902/2902), done. admin /c/GitRepositoryTest $ ls DesignPattern/ test1/
Git add/status/diff/commit/reset/remove/move
<git add>命令可将该文件添加到缓存([.]整个目录add)
$git add <file name> <file name> [.]
<git status>以查看在你上次提交之后是否有修改及文件状态 (-s:简短输出)
[A]表示已缓存
[AM]表示文件在将它添加到缓存之后又有改动,需要再使用git add后才会变成[A]
$git status [-s]
admin MINGW64 /c/GitRepositoryTest $ ls DesignPattern/ test1/ admin MINGW64 /c/GitRepositoryTest $ cd test1/ admin MINGW64 /c/GitRepositoryTest/test1 (master) $ vi file1 admin MINGW64 /c/GitRepositoryTest/test1 (master) $ cp -p file1 file2 admin MINGW64 /c/GitRepositoryTest/test1 (master) $ vi file2 admin MINGW64 /c/GitRepositoryTest/test1 (master) $ ls file1 file2 admin MINGW64 /c/GitRepositoryTest/test1 (master) $ git status -s ?? file1 ?? file2 admin MINGW64 /c/GitRepositoryTest/test1 (master) $ git add file1 file2 warning: LF will be replaced by CRLF in file1. The file will have its original line endings in your working directory. warning: LF will be replaced by CRLF in file2. The file will have its original line endings in your working directory. admin MINGW64 /c/GitRepositoryTest/test1 (master) $ git status -s A file1 A file2 admin MINGW64 /c/GitRepositoryTest/test1 (master) $ vi file1 admin MINGW64 /c/GitRepositoryTest/test1 (master) $ git status -s AM file1 A file2 admin MINGW64 /c/GitRepositoryTest/test1 (master) $ git add file1 warning: LF will be replaced by CRLF in file1. The file will have its original line endings in your working directory. admin MINGW64 /c/GitRepositoryTest/test1 (master) $ git status -s A file1 A file2