`
standalone
  • 浏览: 596391 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Pro Git Tips

 
阅读更多

1. git init

Create a new repo with exsiting project.

 

2. git diff

This command compares what's in your working directory with what's in your staging area. The result tells what changes have not been staged.

 

3. git diff --cached

Shows what you've stage that will go into your next commit. In Git v1.6 or later, you can use git diff --staged.

 

4. git comit -a -m 'comment'

skip staging area. You do not need run git add before you commit.

 

5. git rm

Reimoves the file from your working directory and you don't see it as an untracked file next time.

 

6.  git rm --cached

Remove the file from Git but keep it on your hard disk.

 

7. git mv file_a file_b

 

 8. git log -p -2

This example shows last two commit log. -p shows diff introduced in each commit.

 

9. git log --pretyy=format:"%h %s" --graph

shows branch and merge history. More options:

 

Option	Description of Output
%H	Commit hash
%h	Abbreviated commit hash
%T	Tree hash
%t	Abbreviated tree hash
%P	Parent hashes
%p	Abbreviated parent hashes
%an	Author name
%ae	Author e-mail
%ad	Author date (format respects the –date= option)
%ar	Author date, relative
%cn	Committer name
%ce	Committer email
%cd	Committer date
%cr	Committer date, relative
%s	Subject

 

10. git commit --amend

You can redo your last commit. This can be useful when you forgot to git add some files or you want to edit your commit message.

 

 

11. git reset HEAD

Change file to unstage.

 

12. git checkout -- filename

This discards your current changes. It looks like when you last committed.

 

13. git remote add shortname remote_repo

This command adds a remote repo. git remote -v shows your current remote repo.

 

14. git fetch shortname

This fetches all information you don't have in your repo but in shortname. After this, you have all refs to all branches from that remote. you can run git merge shortname/master to merge it into your master branch.

Notify git fetch pulls all new commit to your working directory but does not automatically merge it.

 

15. git pull

This fetches data and merges.

 

16. git push [remote-name] [branch-name]

E.g., "git push origin master" pushes your master branch to origin repo.

 

17. To be continued...

 

 

 

 

 

 

分享到:
评论
2 楼 standalone 2011-08-14  

Figure 3-31. A history with a topic branch off another topic branch.
Suppose you decide that you want to merge your client-side changes into your mainline for a release, but you want to hold off on the server-side changes until it’s tested further. You can take the changes on client that aren’t on server (C8 and C9) and replay them on your master branch by using the --onto option of git rebase:

$ git rebase --onto master server client
This basically says, “Check out the client branch, figure out the patches from the common ancestor of the client and server branches, and then replay them onto master.” It’s a bit complex; but the result, shown in Figure 3-32, is pretty cool.
1 楼 standalone 2011-08-12  
1. git rm --cahced
从git里面去除但是保留在磁盘上;
2. git rm
删除文件并从git里面去除;
3. git reset HEAD
back到unstaged状态;
4. git checkout -- file
丢弃修改,返回到上次commit的样子。

所以
如果你要放弃修改,回到干净的上次commit的版本,只能用第四个;
如果你git add了一个文件,现在反悔了,那么用第三个可以撤销,不会影响你的更改;
如果你自己的一个test文件误加进了git,你只希望从git里面拿掉,但不希望从磁盘上删除,用第一个;
如果你根本不想要这个文件了,那么用git rm吧。

不知道上面总结的对不对。

相关推荐

    pro git 中文版

    progit中文版 本章介绍开始使用 Git 前的相关知识。我们会先了解一些版本控制工具的历史背景,然后试着在你的系统上把 Git 跑起来,直到最后配置好,可以开始正常的开发工作。读完本章,你就会理解为什么 Git 会...

    ProGit-zh.pdf

    ProGit-zh git 教程 个人收集电子书,仅用学习使用,不可用于商业用途,如有版权问题,请联系删除!

    progit_v2.14

    学习git不可多得的好文档。把这个看会了,用熟了,你就无敌了!!!

    progit_en_v2(progit第二版英文版)

    progit英文版第二版,git里的圣经,学习和使用git的都建议看看。

    Progit中文版

    Git教程progit的中文版,学习Git工具必备。本文档将网站 http://git.oschina.net/progit 的内容打包成chm,方便离线阅读。

    progit-zh git官方文档-中文版

    progit-zh git官方文档-中文版

    progit_v2.1.30.pdf

    git官方中文文档 https://git-scm.com/book/zh/v2/ 亦可自行下载,亦可支持我一下

    progit第二版中文版

    progit第二版中文版 kindle格式 ----- 第一版出版到现在已经过去了四年。到今天,Git 虽然出现了许多改变,但是还有很多重要的事情一如昨日。因为 Git 核心团队对保持向后兼容性异常固执,所以直到今天大多数核心...

    pro git 电子书

    pro git 电子书 pro git 电子书 pro git 电子书 pro git 电子书 pro git 电子书 pro git 电子书 pro git 电子书

    progit中文版.docx

    word文档形式的progit中文版, 来源于http://progit.org/book/zh

    pro git中文版

    pro git 中文版

    Pro Git Pro Git Pro Git

    Pro Git This is the PDF file for the Pro Git book contents. It is licensed under the Creative Commons Attribution-Non Commercial-Share Alike 3.0 license.

    progit 教程 官方版

    本想免费,但是没找到免费方法,可以自行下载 https://github.com/progit/progit2-zh/releases/download/2.1.9/progit_v2.1.9.pdf

    Pro Git中文版

    Pro Git中文版,已经整理了完整的目录

    PRO GIT.pdf

    PRO GIT, english version

    Pro Git.md

    《Pro Git》这本书 [在线版本(第一版)](http://iissnan.com/progit)的整理而成的md档,适合快速了解Git版本控制原理的人员。

    Pro Git(中文版 )

    Pro Git(中文版 )2014 支持 iBook

    Pro git中文版本

    Pro git中文版本,是电子书籍。Pro git中文版本,是电子书籍。

    Pro Git第二版

    《Pro Git》主要介绍了Git使用基础和原理,适合Git爱好者和初学者参考。

    Pro Git》中文版.

    Pro Git》中文版. git一本比较全面的介绍了使用方法,学习GIT必备书籍

Global site tag (gtag.js) - Google Analytics