git学习笔记

Git是一款出色的分布式版本控制工具,但是学习曲线陡峭。这篇文章用来记录我的知识点,本意是给自己做备忘录,因此是全流水帐方式,不做解释,并经常性的更新。

1. git bits up

mkdir try

cd try

mkdir .git

cd .git

mkdir refs #引用

mkdir refs/heads #分支, naming space

mkdir objects #数据

echo ref: refs/heads/master > HEAD

cd ..

运行git status发现已经是一个git repository,效果相当于git init try

2. 创建一个blob

echo "This is my first object" | git hash-object --stdin -w

运行tree .git发现.git目录的objects里出现一个object,效果相当于git add时的object变化。

3. 创建缓存区内容

git update-index --add --cacheinfo 100644 c0e5fef2eb22e44e7e4c7fef4b271de84000c6e8 irene.txt (完整sha号,并给出文件名)

git write-tree 写入tree object

git commit-tree创建commit object

现在需要将头指针指到刚才的提交上: echo 4b04d65b0ad37d4585e1c201b14ad63677e8875d > .git/refs/heads/master

此时运行git log,可以看到有了刚才创建的提交,git status会提示working copy里没有新创建的文件,用git reset --hard HEAD同步。

4. git cat-file 查看内容 -p 打印 -t 类型,后面可以跟sha号,也可以跟引用,例如tag或branch名

5. rebase还可用于reconsider history: git rebase HEAD~10修改最后十次的提交记录

6. git merge-base 打印可用于merge的共同祖先提交,接受多branch参数

7. git show HEAD:somefile可以用:的方式单显示某个文件的内容

8. git rev-parse提供完整的40位sha值

9. git diff

10. 保存分离头指针状态下的提交


11. cherry-pick命令"复制"一个提交节点并在当前复制做一次完全一样的新提交。Rebase在本质上是线性化的自动的cherry-pick。

12. git rebase --onto


上面的命令master分支上重演当前分支从169a6以来的最近几个提交,即2c33a

13. "git push" an individual tag, or "git push --tags" to push all tags

14. "git fetch tag" to fetch a single tag, or "git fetch --tags" to get all tags

15. git tag -a v1 -m "release v1" to create an annotated tag v1

"git show v1" to see the tag details

"git describe" to see the latest tag on the current branch

16.

Sometimes it handy to get a list out of git log that tells you which files were changed since your last release. It’s not straight forward, but very doable with the help of git log and grep. ~ Let’s say you want to view all the changed files since the last tagged release, v1.3.1:

git log --reverse --name-status HEAD...v1.3.1 | grep -e ^[MAD][[:space:]]

As you’re used to, this shows each files that *A*dded, *M*odified or *D*eleted. This command does not squash file changes. So it’s possible for a file to first be added, the deleted, then added again and later modified. The --reverse option shows file changes historically, so the first file changed after the v1.3.1 release is shown first.

17. git error: out of memory, malloc failed

[core]
  packedGitLimit = 128m
  packedGitWindowSize = 128m

[pack]
  threads = 1
  deltaCacheSize = 128m
  packSizeLimit = 128m
  windowMemory = 128m

18. gerrit unpack error, java heap size, out of memory

edit gerrit.config file, add container.heapLimit=16g.

https://git.help.collab.net/entries/24136688-Memory-settings-in-Gerrit-configuration

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值