Why doesn't "go vendor add" work with a revision number
<p>I was getting a compile error which led me to believe that I had the wrong version of a library in my vendor folder. The first task was to determine what revision of the library was correct. I needed to find the version of the library source that contained the string "VolumeCreateRequest". For that I used this trick from the root folder of the library:</p>

<pre><code>git rev-list --all | xargs git grep VolumeCreateRequest
</code></pre>

<p>From that I found the version hash: <code>06f160237426e705ed214a4f087d4aeea32c0a8b</code>:</p>

<p>So then I tried to add that version into my vendor folder
<code>go vendor add github.com/docker/docker/...@06f160237426e705ed214a4f087d4aeea32c0a8b</code></p>

<p>But it doesn't work. When I check the library's version using git it does <em>not</em> report the version I just fetched. </p>

<pre><code>git log -n 1 --pretty=format:"%H"
</code></pre>

<p>The vendor.json file also contains the wrong version</p>

<p>so what's up? After carefully reading the docs I see go vender <em>add</em> just silently ignores the <code>@06f160237426e705ed214a4f087d4aeea32c0a8b</code> on the end of my fetch URI.</p>

<p>The correct command is go vendor <strong>fetch</strong> which supports the @version</p>

<p><code>govendor fetch  github.com/docker/docker/...@06f160237426e705ed214a4f087d4aeea32c0a8b</code> </p>

<p>Another way to accomplish this is to git checkout the version you want of the library, in your GOPATH (i.e. not in your vendor folder), then <code>govendor add</code> the package from your GOPATH</p>

<p>So now I check the git version and we are all good. Then the next problem occurred. Our generate.go file (invoked by <code>go generate</code>) is going in and overwriting the desired version in my <code>vendor.json</code> with what was on my GOPATH.</p>

<p>The sequence in our <code>generate.go</code> is:</p>

<pre><code>//go:generate govendor add +external
//go:generate govendor fetch +missing
//go:generate go vendor sync
</code></pre>

<p>This turned out to be wrong because the add would overwrite my changes, then the sync is ineffectual because vendor.json already infected with wrong version.</p>

<p>The correct sequence is this:</p>

<pre><code>//go:generate govendor sync
//go:generate govendor add +external
//go:generate govendor fetch +missing
</code></pre>

<p>In this way, your customized vendor.json will sync the vendor folder to what is <em>desired</em> first, and only <em>after</em> that will external and missing dependencies be downloaded.</p>

<p>Finally, several dependencies actually would not compile at all do to platform specific stuff. To cure this, I add these lines in generate.go to remove those broken dependencies, <em>after</em> I sync, add, fetch</p>

<pre><code>//go:generate govendor remove github.com/docker/docker/runconfig
//go:generate govendor remove github.com/docker/docker/libcontainerd
//go:generate govendor remove github.com/docker/libcompose/test
//go:generate govendor remove github.com/Microsoft/...
</code></pre>