git常见操作--忽略文件以及常用命令【转】
转自:http://www.cnblogs.com/elfsundae/archive/2011/07/17/2099698.html
References:
http://stackoverflow.com/questions/315911/git-for-beginners-the-definitive-practical-guide
http://www.kernel.org/pub/software/scm/git/docs/
http://progit.org/book/
git安装、配置用户名邮箱、SSH服务器搭建
http://www.cnblogs.com/elfsundae/archive/2011/07/06/2099182.html
Create/List/Remove a new Project/Repository
$ git init
将在当前目录创建一个隐藏的名为".git"的目录。
$ git init
project1
等价于 $ mkdir project1 && cd project1 && git
init
$ git status
检查当前目录是否包含一个git
repo
$ ls .git
查看git目录
$ rm -rf .git/
移除有关git的所有东西
Configure git to ignore files
.gitignore文件可以定义要忽略的文件。详细规则见http://www.kernel.org/pub/software/scm/git/docs/gitignore.html
过滤文件夹: /build/
过滤某种类型的文件: *.tmp
过滤某各文件:
/Build/Products/test.app
!开头表示不过滤: !*.c , !/dir/subdir/
支持通配符: *.[oa]
过滤repo中所有以.o或者.a为扩展名的文件
有三种方法应用过滤:
- 对该repo的所有用户应用过滤:
将 .gitignore 文件放在工作目录的跟目录,编辑.gitignore完成后提交
git add
.gitignore - 仅对自己的repo备份过滤:
添加/编辑你工作目录的$GIT_DIR/info/exclude,例如你的working
copy目录是
~/src/project1 , 则路径为
~/src/project1/.git/info/exclude - 系统全局过滤
创建一个ignore文件,名字随意起,比如我的放在 ~/.gitglobalignore ,然后配置git:
$
core.excludesfile = ~/.gitglobalignore
.gitignore文件示例:
.DS_Store
### build directory
iMochaApp/build/
iMochaSDK/build/
### Testing projects directory
/Testing/
Getting the latest Code

$ git pull <remote> <branch> # fetches the code and merges it into
# your working directory
$ git fetch <remote> <branch> # fetches the code but does not merge
# it into your working directory $ git pull --tag <remote> <branch> # same as above but fetch tags as well
$ git fetch --tag <remote> <branch> # you get the idea

Checking Out Code (clone)
$ git clone user@host.com/dir/to/repo [Target DirName]
Commit Changes
当修改了文件,你需要提交(commit)这些更改。
$ git commit source/main.c
上句将提交
./source/ 目录下的 main.c 文件。
$ git commit
-a
-a标识表示提交所有修改过的文件,但是不提交新增加的文件。新增加的文件需要使用$ git-add 将其添加到git的索引中。
“提交”仅改变你本地repo,如果要提交更改到服务器,需要使用push:
$ git
push <remote> <branch>
查看当前状态
$ git status
可以查看当前工作与那个branch,将要提交什么,提醒你忘记了什么等等...
Undo/Revert/Reset a commit
如果不想让当前的更改生效,返回之前的提交,可以运行如下命令:
# Revert to a previous commit by hash:
$
git-reset --hard <hash>
可使用 HEAD^ 快捷指定上一次提交hash:
# Revert to previous commit:
$ git-reset --hard HEAD^
文件比较
比较命令是 $ git diff
# to compare 2 revisions of a file:
$ git
diff <commit1> <commit2> <file_name>
# to compare current staged file against the repository:
$ git diff --staged <file_name>
#to compare current unstaged file against the repository:
$ git diff <file_name>
How do you see the history of revisions to a file?
$ git log -- filename
git branch
(分支)
git默认分支叫 master
# create a new branch
$ git branch
<branch-name>
# to see a list of all branches in the cureent
repoitory
$ git branch
# if you want
to switch to another branch you can use
$ git
checkout <branch-name>
# to create a new branch and switch to it
in one step
$ git checkout -b
<branch-name>
# to delete a branch:
$ git branch -d <branch-name>
# to create a
branch with the changes from the current branch,do :
$ git stash
$ git
stash branch <branch-name>
How do you merge branches?
if you want to merge a branch(e.g. "master" to "release"), make sure your
current branch is the target branch you'd like to merge into(use $git branch or $git
status to see your current branch).
Then use
$ git merge master
(where
master is the name of the branch you want to merge with the current
branch).
If there are any conflicts, you can use
$ git
diff
to see pending conflicts you have to resolve.
跟踪远程分支
假设你已经clone了一个具有 'some_branch' 分支的远端repo.下面的命令将本地跟踪这个分支:

# list remote branches
git branch -r # start tracking one remote branch
git branch --track some_branch origin/some_branch # change to the branch locally
git checkout some_branch # make changes and commit them locally
.... # push your changes to the remote repository:
git push

创建远程分支

# create a new branch locally
git branch name_of_branch
git checkout name_of_branch
# edit/add/remove files
# ...
# Commit your changes locally
git add fileName
git commit -m Message
# push changes and new branch to remote repository:
git push origin name_of_branch:name_of_branch

删除远程分支
git push [远程名] :[分支名]
$ git push origin :mybranchname
转载请注明:转载自 Elf
Sundae's Blog(http://www.cnblogs.com/elfsundae) (小糊涂闲)
git常见操作--忽略文件以及常用命令【转】的更多相关文章
- 你一定要知道的关于Linux文件目录操作的12个常用命令
写在前面: 1,<你一定要知道的关于Linux文件目录操作的12个常用命令>是楼主收集的关于Linux文件目录操作最常用的命令,包括文件或目录的新建.拷贝.移动.删除.查看等,是开发人员操 ...
- MySQL进口.sql文件和常用命令
MySQL进口.sql文件和常用命令 在MySQL Qurey Brower中直接导入*.sql脚本,是不能一次运行多条sql命令的.在mysql中运行sql文件的命令: mysql> so ...
- git clean 删除忽略文件 和 未被跟踪文件及文件夹
git clean 删除忽略文件 和 未被跟踪文件及文件夹 概念 首先我们需要认清 忽略的文件 和 未被跟踪的文件 忽略的文件:.gitignore 中忽略的文件 未被跟踪的文件:没有被忽略,但是还没 ...
- Git 生成.gitinore忽略文件
Git 生成.gitinore忽略文件 CD到指定目录下: touch .gitinore .gitinore忽略文件 三种方法: # 以'#'开始的行,被视为注释.(#是注释的意思) # 忽略掉所 ...
- 『现学现忘』Git基础 — 19、在Git中进行忽略文件操作
目录 1.忽略文件说明 2.忽略文件的原则 3..gitignore忽略规则 4.忽略文件的三种方式 (1)忽略单个仓库中的文件(远程共用) (2)忽略单个仓库中的文件(本地使用) (3)全局忽略 1 ...
- git中 gitignore 忽略文件操作
通常,.gitignore文件被放置在存储库的根目录中.根目录也称为父目录和当前工作目录.根文件夹包含组成项目的所有文件和其他文件夹.也就是说,您可以将它放在存储库中的任何文件夹中.你甚至可以有多个. ...
- git常见操作指令
由于公司用的是git进行版本管理,所以零零散散的学了一些常用到的git指令: 近日把廖雪峰前辈的git教程看了一遍,感觉操作起来更得心应手,在此做个记录,如有错漏望指正: git init //初始化 ...
- git常见操作---由简入深
常用命令 常用指令 ls 显示文件或目录 -l 列出文件详细信息l(list) -a 列出当前目录下所有文件及目录,包括隐藏的a(all) mkdir 创建目录 -p 创建目录,若无父目录,则创建p( ...
- linux 文件相关常用命令
文件或者目录操控命令 1,cd切换目录. 其中- 代表前一个目录 2,mkdir 新建目录. 加上-p参数可以递归创建多级目录 mkdir -p test1/test2/test3 3,rmdir删除 ...
随机推荐
- VC6.0装了visual assist x回车键不能补全代码的解决方法
问题:VC6.0装了visual assist x补全代码具体怎么用? 输入字母后会像输入法那样出现一个菜单 但是怎么选择菜单里面的内容呢? 什么 回车 ...
- C#读书笔记之并行任务
这两天遇到一个多线程任务优化的问题,现在解决了,把心得用例子的形式记下来. 假设有四个任务: 任务1:登陆验证(CheckUser) 任务2:验证成功后从Web服务获取数据(GetDataFromWe ...
- 双栈排序 noip2008
首先可以看出第一个栈和第二个栈是没什么交集的,那么第一步是对这些元素分别归到两个栈里, 当存在k使i<j<k,a[k]<a[i]<a[j]时,i,j是不能放在一个栈里的,需要一 ...
- 引擎设计跟踪(九.14.2c) 最近一些小的更新
1. bump map与normal map 昨天拿了crytek sponza(http://www.crytek.com/cryengine/cryengine3/downloads)场景测试, ...
- .net程序集强名称签名实践
引用: http://www.cnblogs.com/cpcpc/archive/2011/01/17/2123086.html 强名称是由程序集的标识加上公钥和数字签名组成的.其中,程序集的标识包 ...
- sql server 数据页缓冲区的内存瓶颈分析
查看数据库的计数器: SELECT * FROM sys.dm_os_performance_counters **也可以使用系统的性能计监测器查看. 右键图表-> 添加计数器. ...
- Git常用命令大全
查看.添加.提交.删除.找回,重置修改文件 git help <command> # 显示command的help git show # 显示某次提交的内容 git show $id gi ...
- 理解Linux系统负荷[转]
一.查看系统负荷 在Linux系统中,我们一般使用uptime命令查看(w命令和top命令也行).(另外,它们在苹果公司的Mac电脑上也适用.) 二.一个类比 我们不妨把这个CPU想象成一座大桥, ...
- 十大技巧优化Android App性能
无论锤子还是茄子手机的不断冒出,Android系统的手机市场占有率目前来说还是最大的,因此基于Android开发的App数量也是很庞大的. 那么,如何能开发出更高性能的Android App?相信是软 ...
- 2014多校第七场1003 || HDU 4937 Lucky Number
题目链接 题意 : 给定一个十进制n,让你转化成某个进制的数,让这个数只包含3 4 5 6这些数字,这个进制就成为n的幸运数字,输出有多少幸运数字,例如19,5进制表示是34,所以5是19的一个幸运数 ...