2019-02-16 10:13
浏览 24

分叉存储库上的“ go build”问题

I build a binary file for a GitHub repo (go code), which works fine. no issues. I forked that repo, and modified a single line in the HTML file that has nothing to do with GO code, built the binary file for the new forked repo but the binary it generates refers to the original repo code, can't understand why.

I even cleaned all the code using go clean -i all command and manually removed all the installed code, binary files from $home/go/bin and the repo directory, but it still refers to the original repo code instead of new forked code.

Based on the solution suggested by Tobias, I performed the following steps: enter image description here

After that, I executed go build in that repo directory, but the new binary file still refers to the old code. I even removed the old binary file and generated a new one.

enter image description here

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • dongpan1308
    dongpan1308 2019-02-20 09:18


    At first I thought it was problem with a FORK (which is a common problem experienced with fork of Go language repo's), but it turns out, it was Repo specific problem. One of the dependent libraries had to be reinstalled for the forked repo to work, which was not mentioned in the Original repo docs. Finally, this link helped:, the problem was not generic but repo specific I followed the below steps from above link to resolve the dependency on go-bindata

    go get
    cd $GOPATH/src/
    go build
    点赞 评论
  • doutang6819
    doutang6819 2019-02-16 10:30

    That's a common problem in go. The references system in "location based" so it searches for these files in the "correct" path. Idk if go modules fix this issue, but atleast when not using go modules you'll have to work around it.

    You can solve it by

    Solution 1

    1. Download the original repository you forked by:

    go get

    1. Add your fork as remote

    git remote add awesome-you-fork

    1. You'll have to make changes in the folder of the original downloaded repo and Push and Pull to/from your fork.

    git pull --rebase awesome-you-fork

    git push awesome-you-fork

    Solution 2

    Work around go get: You create the path the original repo would have, but clone your own fork into it. That way you can push & pull to your fork. That may be the better solution

    cd $GOPATH
    mkdir -p {src,bin,pkg}
    mkdir -p src/
    cd src/
    git clone # OR: git clone
    cd tool/
    go get ./...

    These Solutions were found here:

    点赞 评论
  • dtpyvb1873
    dtpyvb1873 2019-02-16 12:03

    The problem with a forked copy of a go packages is when the package is really multiple go packages in one repo, the import statements refer to original base repo, ie:

    This is not an issue for repos with only one go package as it never refers to itself.

    But if it has multiple, ie: package imports

    And then you fork it as:

    Then when the go compiler sees import "" in the source, it goes to download the original version and not your fork.

    Fortunately, go modules solves this.

    Basically, create a go.mod at the top of your forked repo and add: module

    then, the go compiler will assume that you are "orig/repo" regardless of where you actually are checked out from.

    so, when orig/repo/A imports orig/repo/B, it will look locally.

    If there are other imports you need to override that are outside the main forked repo, you can also force dependencies to come from another place using replace

    点赞 评论