软件工程 - 版本管理 - git 的基本实用方法 - 添加一个完整的项目目录的命令的细微差别

1 如何创建一个新的本地git 仓库

$ git init
Initialized empty Git repository in D:/project/weixin_trip_demo/.git/

构建git 仓库的时候,要注意目录深度最后不要包括中文字符

git init 就是在你的本地目录里面增加了一个新的项目仓库,然后,为了方便你可以把你的项目文件先copy过来,当然,也可以逐个制定

2 如何将整个项目文件加到git版本仓库里面?

$ git add .

git add . 是一般用的方法,

 我们首先用git status 来看一下项目仓库的文件夹里有哪些文件

 我是copy了我的项目文件过来到git 仓库里面,然后,可以看到,上面红色的部分就是没有加入到gitchan仓库的文件。

执行

$ git add .


后用git status 查看,我们看到绿色的都是新加入的文件,然后,一下之前红色的文件夹下的文件也被自动加入了

s

但是,我们看git 的帮助定义说明:

git add [--verbose | -v] [--dry-run | -n] [--force | -f] [--interactive | -i] [--patch | -p]
	  [--edit | -e] [--[no-]all | --[no-]ignore-removal | [--update | -u]]
	  [--intent-to-add | -N] [--refresh] [--ignore-errors] [--ignore-missing] [--renormalize]
	  [--chmod=(+|-)x] [--] [<pathspec>…​]

-A--all

--no-ignore-removal

Update the index not only where the working tree has a file matching <pathspec> but also where the index already has an entry. This adds, modifies, and removes index entries to match the working tree.

If no <pathspec> is given when -A option is used, all files in the entire working tree are updated (old versions of Git used to limit the update to the current directory and its subdirectories).

 那么 add . 于 add -A究竟有什么区别呢?

git add -A和 git add .   git add -u在功能上看似很相近,但还是存在一点差别

git add . :他会监控工作区的状态树,使用它会把工作时的所有变化提交到暂存区,包括文件内容修改(modified)以及新文件(new),但不包括被删除的文件。

git add -u :他仅监控已经被add的文件(即tracked file),他会将被修改的文件提交到暂存区。add -u 不会提交新文件(untracked file)。(git add --update的缩写)

git add -A :是上面两个功能的合集(git add --all的缩写)

小结:

要一次加入整个工作目录到git 仓库其实有很多方法,git add . , git add -A都是可以,当然,他们也是有细微的差别,但是,一般使用都是可以的。 

猜你喜欢

转载自blog.csdn.net/yellow_hill/article/details/81090052