Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add git-versions #356

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions bin/git-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/sh
# Gets all the versions of a particular file from the repository
# Places them in a directory called filename_version right next the file

repo_is_clean() {
grep_result=`git status | grep "nothing to commit, working directory clean"`
if [ "$grep_result" = "nothing to commit, working directory clean" ] ; then
echo "repo is clean"
else
echo "repo is not clean"
fi
}

filename=$(basename "$1")
dirpath=$(dirname "$1")
extension="${filename##*.}"
filename="${filename%.*}"

clean=$(repo_is_clean)
if [[ "$clean" == "repo is clean" ]]; then
# create directory
mkdir "$dirpath/${filename}_versions"

# checkout each commit containing that file and save a version of it in filename_versions folder
git log --follow $1 | grep "^commit*" | while read -r line ; do
commit_sha1="${line/commit /}"
git checkout $commit_sha1
cat $1 > "$dirpath/${filename}_versions/${filename}_$commit_sha1"
done

# checkout master again
git checkout master

else
echo "Did not get versions. Working directory not clean. You may need to commit or stash changes."
fi