有没有办法可以查看提交到本地 GitHub 分支的更改,而无需将其推送到 master 分支?

发布于 2024-10-19 19:37:03 字数 200 浏览 1 评论 0原文

我仍在研究 GitHub 和 Heroku,所以请耐心等待。 :)

我在 xyz.com 上有一个网络应用程序。我现在正在做的是对某些文件进行一些代码/UI 更改,提交这些文件,将它们推送到 master 分支,然后刷新 url 以查看这些更改。

我认为这显然是错误的方法,但我不知道如何测试对代码所做的更改,而不必将它们推送到主分支。我怎么能这样做呢?

I'm still figuring GitHub and Heroku out, so please bear with me. :)

I've a web app on, say, xyz.com. What I am doing now is to make some code/UI changes on some files, commit those files, push them to the master branch, and then refreshing the url to see these changes.

I think this is obviously the wrong approach, but I don't know of how else to test changes done to my code without having to push them on to the master branch. How could I do so?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

为你拒绝所有暧昧 2024-10-26 19:37:03

我不太明白您问题的完整版本中的情况(请参阅我的评论,如 icc 询问,为什么不能在本地测试?),但要回答中的问题标题,您可以通过运行以下命令来查看您的 master 版本与 GitHub 上的版本之间的差异:(

git fetch github
git diff github/master master

假设引用您的 GitHub 存储库的远程版本称为 github - 它很可能是 origin< /code> 在你的情况下,你可以使用 git remote -v 来查看所有遥控器。)

进一步解释一下,当你运行 git fetch github 时,git 会更新所有所谓的“远程跟踪分支” - 在大多数情况下,这些分支看起来像 origin/whatevergithub/experiment 等。这些就像这些分支状态的缓存,只有当您运行 git fetch 或成功 git Push 到远程存储库上的该分支时,它们才会更新。因此,一旦您完成此操作以确保 github/master 是 GitHub 上该分支的最新快照,您就可以愉快地将其与本地 master 分支进行比较,使用git diff

I don't quite understand the situation in the full version of your question (see my comment and, as icc asks, why can't you test locally?), but to answer the question in the title, you can see the differences between your master and the version on GitHub by running:

git fetch github
git diff github/master master

(That's assuming that the remote that refers to your GitHub repository is called github - it might well be origin in your case. You can see all your remotes with git remote -v.)

To explain that a little further, when you run git fetch github, git will update all your so-called "remote-tracking branches" - in most cases those are the ones that look like origin/whatever, github/experiment, etc. Those are like a cache of the state of those branches, and they're only updated when you run git fetch or successfully git push to that branch on the remote repository. So, once you've done this to make sure that github/master is a recent snapshot of that branch on GitHub, you can happily compare it with your local master branch using git diff.

默嘫て 2024-10-26 19:37:03

第一:您不推送到主分支,而是推送到远程存储库。您可能应该阅读您的 git

第二:这不是一个好的工作流程,首先您应该提交更改,然后在本地测试它们。完成测试后,您就可以将提交推送到远程存储库。

First: You don't push to the master branch, you push to a remote repo. You should probably read up on your git.

Second: This is not a good workflow, first you should commit your changes and then test them locally. When you are done testing you are ready to push your commits to a remote repo.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文