git bash:如何检查是否有新的提交可用
我和朋友一起使用 git 来协作完成一个项目。他在github上创建了一个repo,其中包含我们每个人名字的文件夹,所以每次我更新一些东西,我都会将其上传到这个文件夹,然后将其推送到github,他也是如此。因此,每次有新的提交时,我们都必须从 github 中提取并将编辑后的文件复制粘贴到我们自己的本地主机 (wamp)。
所以我想问的是:
如何在不检查 github 的情况下检查 git bash 是否有新的提交? Git pull 将拉取我知道的最新版本,但如果我只想先检查怎么办?
假设我的 git 文件夹位于 D://git/project_name。我可以将此文件夹复制到另一个位置(例如 USB 闪存盘),然后从此 USB 执行 git pull 操作吗?
如果我们的方法不起作用,您对我们应该如何使用 git 有什么建议吗?我们使用的是CodeIgniter框架,所以一开始我建议只git推送整个CodeIgniter文件夹,但我的朋友说这是危险的(因为整个配置和数据库都在那里)并且没有必要(因为主系统文件夹很可能不会被触及) )。因此,我们正在使用当前的方法(有两个带有我们名字的文件夹,每次有更新时进行推送和拉取。
I use git with my friend to collaborate on a project. He created a repo in github consisting folders of each of our names, so everytime i update something, I upload it to this folder then push it to github, and so does he. So everytime there's a new commit, we have to pull from github and copy paste the edited files to our own localhost (wamp).
So what i want to ask :
How do I check if there's a new commit from git bash without checking github? Git pull will pull the latest version i know, but what if i just want to check first?
Say my git folder is located in D://git/project_name. Can I copy this folder to another location (for example USB Flash Disk) then do a git pull from this USB?
If our method isn't effective, do you have any proposal on how we should use git? We're using CodeIgniter framework, so at first I proposed to just git push the whole CodeIgniter folders, but my friend said it's dangerous (cos the whole config and database is there) and unnecessary (since the main system folder will most likely be untouched). So we're using this current method (having two folders with our names and pushing and pulling everytime there's an update.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
依次回答您的前两个问题:
origin
在每种情况下都指 GitHub 存储库,您应该只运行git fetch origin
。然后“远程跟踪分支”origin/master
将位于 GitHub 上的 master 版本,您可以使用git diff master origin/master
将其与您的 master 进行比较查看这两个版本之间的差异,或使用git log master...origin/master
查看master
或origin/master< 特有的提交/代码>。
关于是否有更好的方法来做你正在做的事情,恐怕我不太清楚你正在做什么或试图实现明智的评论。然而,在存储库中以每个开发人员的名字命名文件夹(可能)其中包含非常相似的源代码听起来有点可疑 - 您通常会使用分支来处理相同代码的不同版本。
Answering your first two questions in turn:
origin
refers to the GitHub repository in each case, you should just rungit fetch origin
. Then the "remote-tracking branch"origin/master
will be at the version of master on GitHub and you can compare it with your master withgit diff master origin/master
to see the difference between those two versions, orgit log master...origin/master
to see the commits which are unique to eithermaster
ororigin/master
.With regard to whether there is a better way to do what you're doing, I'm afraid I don't understand clearly enough what you're doing or trying to achieve to comment sensibly. However, having folders in the repository named after each developer with (presumably) very similar source code in them sounds a little suspect - you would typically use branches to deal with divergent versions of the same code.
如果您的分支正确跟踪远程分支,您应该能够执行 git status 并查看您是领先还是落后于远程分支以及提交次数。
这让我对 git 有点困惑。以下是三个部分的答案:
1) 通常当您克隆远程存储库时,您需要
-t
标志来跟踪您正在复制的远程分支:2) 如果您忘记这样做,您稍后可以通过执行以下操作来完成此操作:
3)如果您的远程分支与本地分支同名,您应该能够将 git 设置为自动跟踪所有远程分支:
对于您的第二个问题,是的,只要您在您的计算机上使用相同的用户。 Git 使用 SSH 身份验证,因此只要正确的用户运行命令,存储库位于何处并不重要,因此它会随请求发送正确的 SSH 凭据。
If your branch is properly tracking the remote branch, you should be able to do a
git status
and see if you're ahead or behind the remote and by how many commits.This was a little confusing about git for me. Here's the answer in three parts:
1) Usually when you clone a remote repo, you need the
-t
flag to track the remote branch you're copying:2) If you forget to do this, you can always do this later by doing:
3) If your remote branches are the same name as your local branchesyou should be able to just set git to track all remote branches automatically:
For your second question, yes that should be fine as long as you're using the same user on your machine. Git uses SSH authentication so it doesn't matter where the repo is located as long as the right user is running the command so it sends the proper SSH credentials along with the request.
对于其他人,他们来到这里是因为他们想在没有 git fetch 的情况下检查新提交(即不“污染”本地 git):
我发现的一个技巧是使用 git ls-远程并检查远程分支的提交哈希是否与本地分支匹配。
这是一个简单的 bash 脚本,它可以做到这一点:(
我需要这个用于基于 git 的包管理器,它在检查更新时无法调用 git-fetch )。
For anyone else, who came here because they wanted to check for new commits without
git fetch
(i.e. without "polluting" your local git):A trick that I found is to use
git ls-remote
and check if the commit hash of the remote branch matches your local one.Here is a simple bash script that does that:
(I needed this for a git-based package manager, that could not afford to call
git-fetch
when checking for updates).