Git 简易使用笔记


git add . 会把当前目录中所有有改动的文件(不包括.gitignore中要忽略的文件)都添加到git缓冲区以待提交

git add * 会把当前目录中所有有改动的文件(包括.gitignore中要忽略的文件)都添加到git缓冲区以待提交

所以在有要忽略的文件(如:配置文件之类的)有做修改的时候

git add .可以正常工作,会把所有非忽略的所有有改动的文件添加到缓冲区

git add *则会报错,且此几命令不会添加任何文件到缓冲区

本地代码添加修改首先

(1) git add .  从本地代码文件夹添加到索引目录.

(2) git commit -m”提交描述信息”  从代码索引目录提交到HEAD目录

(3) git push  从HEAD 目录提交代码到git 服务器.

本地删除文件

(1) git add -u  把本地代码库中修改或者删除过的文件加入到索引区.

(2) git commit -m “更新信息” 从索引区加入到HEAD 区

(3) git push    把HEAD区提交到git服务器,这时服务器也会把你想删除的文件删掉.

git add -u   和   git add -a  的区别:

git add -u 只是提交你修改过的文件信息到索引区.

git add -a  把修改过的文件信息和未修改过的文件信息全部提交到索引区.

我们可以通过git add -h命令来看git add命令的帮助文档。 git add -h usage: git add [options] [--] …

-n, –dry-run         dry run

-v, –verbose         be verbose

-i, –interactive     interactive picking

-p, –patch           select hunks interactively

-e, –edit            edit current diff and apply

-f, –force           allow adding otherwise ignored files

-u, –update          update tracked files

-N, –intent-to-add   record only the fact that the path will be added later

-A, –all             add changes from all tracked and untracked files

–refresh             don’t add, only refresh the index

–ignore-errors       just skip files which cannot be added because of errors

–ignore-missing      check if – even missing – files are ignored in dry run

git push  提交时出现 warring

升级了git的版本之后,执行git push突然出现了一条警告,

内容如下: warning: push.default is unset; its implicit value is changing in Git 2.0 from ‘matching’ to ‘simple’. To squelch this messageand maintain the current behavior after the default changes, use: git config –global push.default matching To squelch this message and adopt the new behavior now, use: git config –global push.default simple See ‘git help config’ and search for ‘push.default’ for further information.(the ‘simple’ mode was introduced in Git 1.7.11. Use the similar mode ‘current’ instead of ‘simple’ if you sometimes use older versions of Git)

警告的内容是push.default没有设置。

push.default,可以设置为:nothing, matching, upstream, simple, current。

nothing:不推任何东西(要来做什么用?)。 matching:将两边名字能匹配的分支推上去。 upstream:将当前分支推到它的upstream分支。

simple:将当前分支推到它的upstream分支,但名字不匹配时拒绝。这是最安全的选项并且git 2.0之后会默认为这个。

current:将当前分支推到与它同名的分支上。

建议您进行如下设置:git config –global push.default simple。


回到顶部