Git学习笔记

        学习progit过程中,在文档里做了笔记,在百度网盘和google drive里做了共享。

        百度网盘:http://pan.baidu.com/s/1pJyLvqr

        Google drive: https://drive.google.com/file/d/0B2nQbLVvDDc2N0QxZFd0b1k0a0k/edit?usp=sharing

1、列出repository里的文件

         git ls-files

2、 –n, --dry-run

         该命令选项的意思是:不进行实际的操作,只是提示该命令如果没有添加该选项的话,会执行的操作。如“git rm *.c –n”,并不会删除所有的.c文件,但会给出提示。

3、Windows下建立repository

         从“我的电脑”里进入要建立repository的文件夹,右击鼠标,有”Git Init Here”, “Git Bash”的选项,可以很方便的建立repository,无需再从Git Bash里进入相应目录。

4、从repository里删除文件

         git rm filename

         注意:如果直接用该命令不仅会将该文件从repository删除,也将删除从本地磁盘中删除。如果只想从repository中删除的话,需要加”- -cached”选项。

5、gitrm vs git clean

         git-rm - Remove files from the working tree and from the index

         git-clean -  Remove untracked files from the working tree

6、比较两个分支的内容

         git diff branch_1..branch_2

         That will produce the diff between the tips of the two branches. If you'd prefer to find the diff from their common ancestor to test, you can use three dots instead of two:

         git diff branch_1...branch_2

7、Windows 下忽略不想加入repository的文件

         In Windows, youcan enter the repository directory and use vim to create .gitignore file in GitBash.

         下面是我自己的一个.gitignore文件内容:

*~

*.pdf

.gitignore

 

8、用gitk查看所有的branch,commit记录

         “gitk - -all”

         查看所有的commit记录

         “git log - -all” or “git log - -graph - -all”

 

9、在Windows下删除repository

         需要删除.git文件夹,该文件夹是隐藏的。

 

10、一直都在master上操作,没有建立其他的分支;此时checkout到旧的commit,然后又想切回到刚才最新的commit,如何做?

         用到的命令肯定是checkout,但是想通过git log找到最新的commit时,确找不到,因为” Git resets your working directory to look like the snapshot of the commit that the branch you check out points to. It adds, removes, and modifies files automatically to make sure your working copy is what the branch looked like on your last commit to it.”。

         这时可以用”git reflog”命令来查看之前所有的checkout、commit记录,从而就可以用checkout切换到之前最新的状态。

http://stackoverflow.com/questions/7263924/git-checkout-reverted-code-to-older-commit-how-to-revert-back


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值