I made a script that compiles a program (box86), packages it into a debian package every week, and uploads it to my apt repo (hosted on github).
for the version of each package I use the git tag (0.2.1 for example) and the git commit hash (638b341 for example) and put them like this: tag+sha1 (0.2.1+638b341 for example). note that checkinstall that is used for packaging adds a -1 to the end, so in my example, the version would be 0.2.1+638b341-1.

after adding the repo to my apt sources, apt gets the wrong version. I tried several fixes including adding a "epoch", incrementing the -1, and adding a number before and incrementing it in each version (1-version). but none of them worked (or would be practical).

I'm pretty sure I have to add something to the version, but I don't know what.

any help is appreciated.

  • What version does apt get? Mar 20, 2021 at 17:07
  • @StephenKitt as of now the available versions are: 0.2.1+044326d3-1, 0.2.1+13cce1a4-1, 0.2.1+638b341b-1, 0.2.1+e478b993-1, and 0.2.1+f370bf77-1. the latest is: 0.2.1+638b341b-1. apt downloads: `0.2.1+13cce1a4-1 Mar 20, 2021 at 17:14

1 Answer 1


All else being equal, apt prefers later versions. Because hashes don’t increase with time, using them in versions can cause the problem you’re seeing.

There are two common workarounds: adding a monotonically-increasing number before the hash, or adding the date, again before the hash.

Taking the latter approach, for a build done today you’d have 0.2.1+20210320.thehash-1, replacing “thehash” as appropriate. Better yet, you can use

git log --date=format:%Y%m%d --pretty=0.0~git%cd.%h

to generate the version number; this is supported by uscan and can be used to automatically update to the current head of a git repository.

  • what is the date command to get the current date in that format? Mar 20, 2021 at 17:17
  • found a way: date +"%F" | sed 's/-//g' Mar 20, 2021 at 17:22
  • 1
    Yes, all versions need to follow this pattern for it to work in all cases (until you update the main version, e.g. 0.2.2-1 for a proper 0.2.2 release). 0.2.1+13cce1a4-1 sorts lower than 0.2.1+20210320.638b341b-1 so the behaviour you’re getting is still surprising... Mar 20, 2021 at 19:23
  • 1
    I made a build today and apt downloaded it even though it was the same commit hash as yesterday, so it works. Thanks a lot! Mar 21, 2021 at 14:01
  • 1
    @ItaiNelken if you change the version scheme, you might want to change the epoch number so that versions in the old scheme never sort after versions in the new scheme.
    – muru
    Mar 21, 2021 at 15:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .