Git开发实战(四)之删除文件、忽略操做(rm,gitignore)

1、删除本地文件 git rm/commitgit

      1.好比,我先查看当前目录有哪些文件,而后选择删除message文件,而后再查看当前状态,咱们能发现git已经把咱们删除的message文件记住了,git提示咱们已经在本地代码中把message文件删除了,可是没有提交到本地仓库中,也就是说若是咱们不提交,git是不认可把message文件删除的!咱们发现看到提示,咱们要删除文件实际上是要用git rm 文件名 命令才能将删除这个改动提交到待提交列表中,咱们再次执行git rm message命令,这个时候咱们能够看到,咱们已经将改动放到了待提交列表中,提示咱们提交到本地仓库中去!数据库

aibin@XiaoAibin MINGW64 ~/Desktop/test_git (master)
$ ls
message  README

aibin@XiaoAibin MINGW64 ~/Desktop/test_git (master)
$ rm message

aibin@XiaoAibin MINGW64 ~/Desktop/test_git (master)
$ ls
README

aibin@XiaoAibin MINGW64 ~/Desktop/test_git (master)
$ git status
On branch master
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:    message

no changes added to commit (use "git add" and/or "git commit -a")

aibin@XiaoAibin MINGW64 ~/Desktop/test_git (master)
$ git rm message
rm 'message'

aibin@XiaoAibin MINGW64 ~/Desktop/test_git (master)
$ git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        deleted:    message

      2.咱们将删除改动,正式提交到本地仓库中去,而后查看本地提交的改动;vim

aibin@XiaoAibin MINGW64 ~/Desktop/test_git (master)
$ git commit -m '删除了message文件'
[master d4d2af3] 删除了message文件
 1 file changed, 0 insertions(+), 0 deletions(-)
 delete mode 100644 message

aibin@XiaoAibin MINGW64 ~/Desktop/test_git (master)
$ git show d4d2af
commit d4d2af303b2f512b64336a8ed6568a64a48cf9cf
Author: kevinShaw <aibinxiao@126.com>
Date:   Thu Oct 26 09:48:40 2017 +0800

    删除了message文件

diff --git a/message b/message
deleted file mode 100644
index e69de29..0000000

      以上,就是删除本地文件的操做!后端

2、忽略文件.gitignorebash

      1.使用理由:由于在协同开发的时候,好比同时作后端开发,每一个人的数据库的密码是不同的,若是归入版本控制,每次pull代码后都要从新修改(固然你也能够不提交这个文件),因此数据库的配置文件就不要归入git的版本控制中去!版本控制

      2.好比,咱们在原来的目录中建立一个database.yml数据库配置文件,若是不将它归入忽略版本控制中,git就会提示咱们这个文件没有提交到待提交列表,没有放到仓库中管理,就会很烦;code

aibin@XiaoAibin MINGW64 ~/Desktop/test_git (master)
$ touch database.yml

aibin@XiaoAibin MINGW64 ~/Desktop/test_git (master)
$ git status
On branch master
Untracked files:
  (use "git add <file>..." to include in what will be committed)

        database.yml

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

      3.这个时候,咱们就能够建立一个.gitignore文件(注意:这个文件要和.git文件在同一个目录中),来将咱们不须要归入版本控制的文件添加到这个文件中去,git就不会再提示你了。咱们再次查看git status,发现以前的database.yml文件已经再也不有提示信息了,如今只有.gitignore文件的提示信息;后端开发

aibin@XiaoAibin MINGW64 ~/Desktop/test_git (master)
$ vim .gitignore

咱们在编辑.gitignore中添加*.yml,就表示全部的以.yml结尾的文件都将再也不归入版本控制中

aibin@XiaoAibin MINGW64 ~/Desktop/test_git (master)
$ git status
On branch master
Untracked files:
  (use "git add <file>..." to include in what will be committed)

        .gitignore

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

      4.咱们提交.gitignore文件开发

aibin@XiaoAibin MINGW64 ~/Desktop/test_git (master)
$ git add .gitignore
warning: LF will be replaced by CRLF in .gitignore.
The file will have its original line endings in your working directory.

aibin@XiaoAibin MINGW64 ~/Desktop/test_git (master)
$ git commit -m '忽略.yml的配置文件'
[master 04c9dd8] 忽略.yml的配置文件
 1 file changed, 1 insertion(+)
 create mode 100644 .gitignore

      以上就是.gitignore文件的操做,能够根据本身须要,配置须要忽略的一些文件!it

 

本文为原创文章,若是对你有一点点的帮助,别忘了点赞哦!比心!如需转载,请注明出处,谢谢!

相关文章
相关标签/搜索