git 基本操作

1。拉取git的库: 

   git clone https://github.com/dachuizhuzhiqiang/springcloudConfig/

2.检查当前文件状态

git status
$ git status
On branch master
Your branch is up to date with 'origin/master'.

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

        README

nothing added to commit but untracked files present (use "git add" to track)

3.跟踪新文件

git add README

$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        new file:   README

4.状态简览

$ git status -s
A  1234.txt
A  README
 M "\346\205\242sql.txt"
MM "\346\205\243sql.txt"
?? 1232.gitignore
新添加的未跟踪文件前面有 ?? 标记,新添加到暂存区中的文件前面有 A 标记,修改过的文件前面有 M 标记。
你可能注意到了 M 有两个可以出现的位置,出现在右边的 M 表示该文件被修改了但是还没放入暂存区,
出现在靠左边的 M 表示该文件被修改了并放入了暂存区。 例如,上面的状态报告显示: README 文件在工作区被修改了但是
还没有将修改后的文件放入暂存区,lib/simplegit.rb 文件被修改了并将修改后的文件放入了暂存区。
而 Rakefile 在工作区被修改并提交到暂存区后又在工作区中被修改了,所以在暂存区和工作区都有该文件被修改了的记录。
5.查看已暂存和未暂存的修改
git diff
6.提交更新
git commit -m "2019-01-03 zzq test"
[master 4558224] 2019-01-03 zzq test
 3 files changed, 3 insertions(+), 68 deletions(-)
 create mode 100644 1234.txt
 create mode 100644 README
 rewrite "\346\205\242sql.txt" (100%)

  7.调货使用暂存区域(加 -a)

git commit -a -m "2019-01-03 zzq test"

8.移除文件
要从 Git 中移除某个文件,就必须要从已跟踪文件清单中移除(确切地说,是从暂存区域移除),然后提交。 可以用 git rm 命令完成此项工作,
并连带从工作目录中删除指定的文件,这样以后就不会出现在未跟踪文件清单中了。
$ rm 12345.txt $ git status On branch master Your branch is ahead of 'origin/master' by 1 commit. (use "git push" to publish your local commits) Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: 1232.oafas new file: 12345.txt Changes not staged for commit: (use "git add/rm <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) deleted: 12345.txt

$ git rm 12345.txt
rm '12345.txt'

$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)

Changes to be committed:
(use "git reset HEAD <file>..." to unstage)

new file: 1232.oafas

我们想把文件从 Git 仓库中删除(亦即从暂存区域移除),但仍然希望保留在当前工作目录中。 换句话说,你想让文件保留在磁盘,但是并不想让 Git 继续跟踪。 当你忘记添加 .gitignore 文件,不小心把一个很大的日志文件或一堆 .a 这样的编译生成文件添加到暂存区时,这一做法尤其有用。 为达到这一目的,使用 --cached 选项:

 

$ git rm --cached 12345.txt
rm '12345.txt'

$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)

Changes to be committed:
(use "git reset HEAD <file>..." to unstage)

new file: 1232.oafas

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

12345.txt

 

 

 

9.移动文件

git mv test test.txt

$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        new file:   1232.oafas
        renamed:    test -> test.txt

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

        12345.txt

其实,运行 git mv 就相当于运行了下面三条命令:

$ mv README.md README
$ git rm README.md
$ git add README

三。

查看提交历史  $ git log

$ git log -p -2 最近两次的提交
$ git log --stat 每次提交的简略的统计信息

2.5 Git 基础 - 远程仓库的使用

如果想查看你已经配置的远程仓库服务器,可以运行 git remote 命令。 它会列出你指定的每一个远程服务器的简写。 如果你已经克隆了自己的仓库,那么至少应该能看到 origin - 这是 Git 给你克隆的仓库服务器的默认名字:

$ git remote
origin

你也可以指定选项 -v,会显示需要读写远程仓库使用的 Git 保存的简写与其对应的 URL。

git remote -v

添加远程仓库

我在之前的章节中已经提到并展示了如何添加远程仓库的示例,不过这里将告诉你如何明确地做到这一点。 运行 git remote add <shortname> <url> 添加一个新的远程 Git 仓库,同时指定一个你可以轻松引用的简写

从远程仓库中抓取与拉取

$ git fetch [remote-name]

推送到远程仓库

   $ git pull origin master

$ git push origin master
 
 

 

 

 


posted @ 2019-01-03 17:37  anxbb  阅读(165)  评论(0编辑  收藏  举报