Search code examples
gitmsysgit

How to assign value of a git command to a variable using script


Is it possible to assign the value a git command like git rev-list -n 1 --before=<timestamp> master to a variable.

Ex: commits = git rev-list -n 1 --before=<timestamp> master

then I want to something like

git tag RELEASE_01 $commits[0]

My repository is on a windows XP system and I'm using msysgit.

Thank you


Solution

  • You can use backticks or $() to evaluate one command within another, for instance:

    git tag RELEASE_01 `git rev-list -n 1 --before=<timestamp> master`