shithub: git9

ref: a08453bf28d8178919b62d01b73e56c209f5b4d1
dir: /revert/

View raw version
#!/bin/rc
rfork e
. /bin/git/common.rc

usage='
	git/revert [-c query] file [...]
		-c        revert to commit "query" (default: HEAD)
'

commit=/mnt/git/HEAD
nl='
'
pfx=`{pwd}
while(~ $1 -* && ! ~ $1 --){
	switch($1){
	case -c;
		commit=`{git/query -p $2};
		shift
	case *;
		usage
	}
	shift
}

if(! cd `{git/conf -r}){
	echo not a git repository >[1=2]
	exit notgit
}
pfx=`{echo $pfx | sed 's@^'^`{pwd}^'@@g'}
if(~ $#pfx 0)
	pfx=''
git/fs

for(f in `$nl{cd $commit/tree/ && walk -f ./$pfx/$*})
	cp -- $commit/tree/$pfx/$f ./$pfx/$f