git的一些操作

来源:互联网 发布:SWAMM软件 编辑:程序博客网 时间:2024/05/16 11:31

1.从现有仓库克隆

[python] view plaincopy在CODE上查看代码片派生到我的代码片
  1. git clone git://github.com/schacon/grit.git  

2.检查当前文件状态

[python] view plaincopy在CODE上查看代码片派生到我的代码片
  1. git status  

3.跟踪新文件

[python] view plaincopy在CODE上查看代码片派生到我的代码片
  1. git add XXX  

4.忽略某些文件

项目根目录下新建.gitignore文件
[python] view plaincopy在CODE上查看代码片派生到我的代码片
  1. $ cat .gitignore  
  2. *.[oa]  
  3. *~  

第一行告诉 Git 忽略所有以 .o 或 .a 结尾的文件。一般这类对象文件和存档文件都是编译过程中出现的,我们用不着跟踪它们的版本。第二行告诉 Git 忽略所有以波浪符(~)结尾的文件,许多文本编辑软件(比如 Emacs)都用这样的文件名保存副本。此外,你可能还需要忽略 log,tmp 或者 pid 目录,以及自动生成的文档等等。要养成一开始就设置好 .gitignore 文件的习惯,以免将来误提交这类无用的文件。文件 .gitignore 的格式规范如下:

  • 所有空行或者以注释符号 # 开头的行都会被 Git 忽略。
  • 可以使用标准的 glob 模式匹配。
  • 匹配模式最后跟斜杠(/)说明要忽略的是目录。
  • 要忽略指定模式以外的文件或目录,可以在模式前加上惊叹号(!)取反。

5.查看已暂存和未暂存的更新

[python] view plaincopy在CODE上查看代码片派生到我的代码片
  1. git diff  

6.提交更新

[python] view plaincopy在CODE上查看代码片派生到我的代码片
  1. git commit -m "Story 182: Fix benchmarks for speed"   

7.跳过使用暂存区域

[python] view plaincopy在CODE上查看代码片派生到我的代码片
  1. git commit -a -m 'added new benchmarks'   

8.移除文件

[python] view plaincopy在CODE上查看代码片派生到我的代码片
  1. git rm grit.gemspec  

9.移动文件

[python] view plaincopy在CODE上查看代码片派生到我的代码片
  1. git mv file_from file_to  

10.查看提交历史

[python] view plaincopy在CODE上查看代码片派生到我的代码片
  1. git log  

11.取消对文件的修改

[python] view plaincopy在CODE上查看代码片派生到我的代码片
  1. git checkout -- benchmarks.rb  

12.查看当前的远程库

[python] view plaincopy在CODE上查看代码片派生到我的代码片
  1. git remote -v  

13.添加远程仓库

[python] view plaincopy在CODE上查看代码片派生到我的代码片
  1. git remote add pb git://github.com/paulboone/ticgit.git  

14.从远程仓库抓取数据

[python] view plaincopy在CODE上查看代码片派生到我的代码片
  1. git fetch [remote-name]  

15.推送数据到远程仓库

[python] view plaincopy在CODE上查看代码片派生到我的代码片
  1. git push origin master  

16.远程仓库的删除和重命名

[python] view plaincopy在CODE上查看代码片派生到我的代码片
  1. git remote rename pb paul  
0 0
原创粉丝点击