git常见问题

[TOC] 1.git删除文件 当我们想要删除某个文件,直接删除是没有用的. [root@vultr hexo]# git status # On branch master nothing to commit (working directory clean) [root@vultr hexo]# rm source/_posts/test.txt rm: remove regular empty file `source/_posts/test.txt'? y [root@vultr hexo]# git status # On branch master # Changed but not updated: # (use "git add/rm <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # deleted: source/_posts/test.txt # no changes added to commit (use "git add" and/or "git commit -a") [root@vultr hexo]# git add . [root@vultr hexo]# git commit -m "delete test file " # On branch master # Changed but not updated: # (use "git add/rm <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # deleted: source/_posts/test.txt # no changes added to commit (use "git add" and/or "git commit -a") 直接使用rm 删除的仅仅是工作区的文件,并没有删除暂存区,所以commit 不会生效. 由于平时使用基本都是修改或者增加新文件,大家习惯用 git add 命令,而忽略了 git rm , 其实在git status 都有提示,仔细看看就知道了. ...

August 26, 2016

Git 使用指南

[TOC] Git 使用指南 git命令 版本控制 Git 简介 Git是目前世界上最先进的分布式版本控制系统。 如果你是小白,可以先看廖雪峰的官方教程 专用名词 Workspace: 工作区 Index / Stage: 暂存区 Repository: 仓库区 ( 本地版本库 ) Remote: 远程仓库 ( 远程仓库 / 远程版本库 ) 代码库 在当前目录新建一个Git代码库 git init 新建一个目录,将其初始化为Git代码库 git init [project-name] 克隆代码库 git clone [url] Git 配置 Git的配置文件为 .git/config ,它可以在用户主目录下(全局配置),也可以在项目目录下(项目配置)。 显示当前Git配置 git config --list 编辑Git配置文件 git config -e [--global] 设置代码时的用户信息 建议设置此项,后面的操作会很方便 git config [--global] user.name "[name]" git config [--global] user.email "[email address]" 增加/删除文件 操作之前先执行 git status 查看一下状态 ...

February 13, 2016