您的位置:首页 > 其它

使用 git 命令行实现 commit 到 bare 仓库

2014-03-24 10:41 851 查看
这是一个shell脚本,可以直接执行,观察它的输出,然后再去检查bare仓库,看看结果是否正确。

#!/bin/sh

cd ~

rm -rf bare.git

echo "-------> create bare repo"
echo ""
git init --bare bare.git
cd bare.git

echo ""
echo "-------> initial commit: test.txt"
echo ""
# create object
obj=`echo 'test content' | git hash-object -w --stdin`
# create index
git update-index --add --cacheinfo 100644 $obj test.txt
# create tree
tree=`git write-tree`
git ls-tree $tree
echo ""
# commit
commit=`echo 'initial commit' | git commit-tree $tree`
git log --stat --pretty=oneline $commit

echo ""
echo "-------> second commit: new.txt"
echo ""
# second commit
obj1=`echo 'new content' | git hash-object -w --stdin`
git update-index --add --cacheinfo 100644 $obj1 new.txt
tree1=`git write-tree`
git ls-tree $tree1
echo ""
commit1=`echo 'second commit' | git commit-tree $tree1 -p $commit`
# create refs
git update-ref refs/heads/master $commit1
# update head
git symbolic-ref HEAD refs/heads/master
git log --stat --pretty=oneline HEAD

echo ""
echo "-------> third commit: edit test.txt"
echo ""
# delete index
rm index
# create index from HEAD
git read-tree HEAD
obj2=`echo 'edited test content' | git hash-object -w --stdin`
git update-index --cacheinfo 100644 $obj2 test.txt
tree2=`git write-tree`
git ls-tree $tree2
echo ""
commit2=`echo 'third commit' | git commit-tree $tree2 -p $commit1`
# update refs
git update-ref refs/heads/master $commit2
git log --stat --pretty=oneline HEAD
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐