git

https://git-scm.com/docs
https://git-scm.com/book/en/v2
猴子都能懂得git入门
http://backlogtool.com/git-guide/cn/

配置文件

配置文件有3级

1 /etc/gitconfig 系统级的配置文件 使用 --system 参数设置到

2 ~/.gitconfig or ~/.config/git/config 用户级的配置文件 --global 参数设置到

3 .git/config 在某个项目级别的配置文件。

每一级会覆盖掉上一级相同的设置 ,如.git/config 会覆盖掉 /etc/gitconfig中相同的设置

名字和邮箱在提交代码时会用到

$ git config --global user.name "John Doe"
$ git config --global user.email johndoe@example.com

检查你的设置

git config --list
user.name=John Doe
user.email=johndoe@example.com
color.status=auto
color.branch=auto
color.interactive=auto
color.diff=auto
...

查看某个具体key的值

git config user.name
John Doe

git status
git add 含义 添加文件到 下一次提交。

Ignoring Files
.gitignore
eg

*.[oa]
*~
*.log

ignore file 规则

Blank lines or lines starting with # are ignored.

Standard glob patterns work.

You can start patterns with a forward slash (/) to avoid recursivity.

You can end patterns with a forward slash (/) to specify a directory.

You can negate a pattern by starting it with an exclamation point (!).

https://git-scm.com/book/en/v2/Git-Basics-Recording-Changes-to-the-Repository

另一个.gitignore

# no .a files
*.a

# but do track lib.a, even though you're ignoring .a files above
!lib.a

# only ignore the TODO file in the current directory, not subdir/TODO, 如果还有一个目录 /a/TODO  就不会ignore
/TODO

# ignore all files in the build/ directory
build/

# ignore doc/notes.txt, but not doc/server/arch.txt
doc/*.txt

# ignore all .pdf files in the doc/ directory and any of its subdirectories
doc/**/*.pdf

git diff 显示的是 track的文件中, 更改了,但还没有 staged的部分。

git diff --staged 比较的是 ,staged的文件 和上一次提交的不同。

git commit -a -m 'added new benchmarks' 这个命令会跳过 git add 的环节, 不推荐。

git mv file_from file_to 很神奇

git log
查看git 历史,最好还是借助 图形化的工具,如 sourcetree

git commit --amend 修改注释

撤销当前修改
git checkout --
撤销全部修改
git checkout . 这个命令要小心执行,不然你写的代码就瞬间都没了。

远端

git remote
git remote -v
git remote add
git remote add pb https://github.com/paulboone/ticgit
git fetch origin 获取远端的data fetch只是下载,并不会自动帮你merge
git pull origin 等于 git fetch + git merge
git push [remote-name] [branch-name] 推代码到远端
如果你推代码时,别人又提交了新的代码, 你的push会被拒绝。 你需要先fetch到最新的代码,和自己的合并到一起 ,然后再push。

git remote rename pb paul 修改远端的名字
git remote remove paul 删除远端

Tag

git checkout -b version2 v2.0.0 检出tag=v2.0.0 到 分支 version2

git add . 把所有修改加入 staged

checkout

把远程的分支 checkout到本地
git checkout -b [分支名] [远程名]/[分支名]

posted on 2017-07-27 11:45  fupeng  阅读(119)  评论(0编辑  收藏  举报

导航