开发者

Shell script: find git folder and execute git command?

I have several git repo in folder and subfolder and i want to cleanup using git reset --hard, can someone guide me ?

find /home/me/src -type d -name ".git" -开发者_StackOverflowprint

and execute find ".git" repo

git --git-dir=/home/me/src/find1/.git reset --hard
git --git-dir=/home/me/src/find2/.git reset --hard
git --git-dir=/home/me/src/subfolder/find3/.git reset --hard


git reset --hard only works with a working directory. I'm afraid your commands won't do what you expect. You'd have to cd into the working directory of the git repository (assuming the .git directory is contained within your working directory)

find /home/me/src -type d -name '.git' -print0 \
| xargs -0 sh -c 'cd "${1%/.git}"; git reset --hard;' -


Try below script. Hope it helps

find /home/me/src -name ".git" -type d -exec "git reset --hard {}" \;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜