本文共 3048 字,大约阅读时间需要 10 分钟。
查看是否存在文件需要上传
git status git add . git commit -m '' 创建远程仓库 git remote add origin 116.255.146.153:ruby_cd/work_daily_project.git 更新 git fetch 116.255.146.153:ruby_cd/work_daily_project.git master 合并代码 git merge origin/master 提交 git push origin master==========================================================
git 基于文件夹(工作树)进行版本控制,在一个文件夹中创建 git版本库:
$ cd project/ $ git init Initialized empty Git repository in .git/
| 输出信息:在当前文件夹的 .git/ 目录下创建版本库 |
将文件提交到 git索引:
git add file1 file2 file3 ……
更方便的作法是将当前文件夹中的所有文件全部加入到索引中
git add .
.gitignore
文件中设置排除的文件(通常把临时文件排除) 注意 | |
---|---|
git 只负责管理被索引的文件 |
此时,文件还没有被提交到版本库。向版本库提交第一个版本:
git commitgit commit -m "备注"
| 调用系统默认编辑器编辑备注内容 |
使用 git status 命令查看版本库状态。先创建一个演示版本库:
mkdir sandbox #新建一个文件夹cd sandbox/ #进入该文件夹git init #初始化版本库touch a b #新建 a b 两个文件git add . #将这两个文件提交到索引git commit -m "创建git版本库" #将第一个版本提交到版本库
这时使用 git status
查看版本库状态:
# On branch masternothing to commit (working directory clean)
对文件进行一些操作:
vi a #编辑 arm b #删除 btouch c #新建 c
再用 git status
查看:
# On branch master #在 master 分支上# Changes to be committed: #已提交到索引,等待提交到版本库(其实本例中没有这一段)# (use "git reset HEAD..." to unstage)## new file: e # modified: f ## Changed but not updated: #改动未提交到索引# (use "git add/rm ..." to update what will be committed)## modified: a# deleted: b## Untracked files: #文件未提交到索引# (use "git add ..." to include in what will be committed)## cno changes added to commit (use "git add" and/or "git commit -a")
注意 | |
---|---|
如果只是想删除该文件夹中的版本库,只要删除 .git/ 目录即可 rm -rf .git |
git 初始化后,会在.git/
目录下创建一个版本库,其中.git/config
为配置文件。
为当前版本库添加用户信息[]:
[user] name = kardinal email = 2999am@gmail.com
也使用全局用户信息,在~/.gitconfig
中写入上述内容,或者使用命令:
git config --global user.name "kardinal"git config --global user.email 2999am@gmail.com
在~/.gitconfig
文件中添加如下语句,使用容易阅读的彩色来输出信息:
[color] branch = auto diff = auto status = auto
或者自己定义:
branch.current # color of the current branchbranch.local # color of a local branchbranch.plain # color of other branchesbranch.remote # color of a remote branchdiff # when to color diff outputdiff.commit # color of commit headersdiff.frag # color of hunk headersdiff.meta # color of metainformationdiff.new # color of added linesdiff.old # color of removed linesdiff.plain # color of context textdiff.whitespace # color of dubious whitespacestatus # when to color output of git-statusstatus.added # color of added, but not yet committed, filesstatus.changed # color of changed, but not yet added in the index, filesstatus.header # color of header textstatus.untracked # color of files not currently being trackedstatus.updated # color of updated, but not yet committed, files
转载地址:http://fdadi.baihongyu.com/