git pull 不拉所有东西

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9688867/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 13:11:25  来源:igfitidea点击:

Git pull not pulling everything

git

提问by thiagofm

I have a server where there's some config that I don't properly know where i just git pull and it gets what is in a github repo, then restart it in order to deploy.

我有一个服务器,那里有一些配置,我不知道我只是 git pull 在哪里,它获取了 github 存储库中的内容,然后重新启动它以进行部署。

The thing is, there's a commit which isn't my latest, that isn't really on my server. The files aren't in .gitignore. How do I assure that a pull, pulled a commit?

问题是,有一个提交不是我的最新提交,也不是真的在我的服务器上。这些文件不在 .gitignore 中。我如何确保拉,拉提交?

I really don't know how to fix it, I'm thinking about restarting everything :(

我真的不知道如何解决它,我正在考虑重新启动一切:(

14:41][root@someserver] someserver_dir (master)$ git status
# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   Gemfile
#   modified:   Gemfile.lock
#   modified:   config/assets.yml
#   modified:   config/database.yml
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   randomfiles

回答by Amber

If you always want your server version to reflect a commit from your repo, it's probably better to use git resetinstead of git pull- that way you never invoke merge functionality, but instead set all of the files to exactly what they are in the commit you reset to. For example:

如果您总是希望您的服务器版本反映您的存储库中的提交,则最好使用git reset而不是git pull- 这样您就不会调用合并功能,而是将所有文件设置为您重置的提交中的确切内容。例如:

git fetch origin master
git reset --hard FETCH_HEAD

回答by invinciblemuffi

You can use git pull origin branch_name of the github.

您可以使用git pull origin branch_name of the github.

Ex: If I have a production branch on GitHub, then I will write git pull origin productionwhich will give me all the latest commits.

例如:如果我在 GitHub 上有一个生产分支,那么我会写git pull origin production它会给我所有最新的提交。

Only doing git pullsometimes does not give you the latest commits of production branch even though you are working on that branch and committing it.

只有这样做git pull,有时不给你,即使你工作的一个分支,并承诺其生产分支的最新提交。