git 在 github 上更新我的存储库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/48349103/
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
update my repository on github
提问by FeRcHo
I just went up to githubthe project that was working locally on my computer. everything went well and I could upload all my files .. now I would like to know how I can update my repository if I make some changes to my project locally try the following commands:
我刚刚去github上我的计算机上本地工作的项目。一切顺利,我可以上传我的所有文件..现在我想知道如果我在本地对我的项目进行一些更改,我该如何更新我的存储库,请尝试以下命令:
git add.
git pull origin master
I think I'm forgetting something, or I'm using the commands incorrectly, what would be the correct way?
我想我忘记了一些东西,或者我使用的命令不正确,正确的方法是什么?
回答by user1561783
Your work flow for ensuring that your changes are added correctly to your remote github repo in "normal" cases should follow these stages ..
确保在“正常”情况下将更改正确添加到远程 github 存储库的工作流程应遵循以下阶段..
(1) git status
Will always tell you what is uncommitted and what needs to be "added" (staged) for committing to your local repo. In fact git will hint to you what it thinks is the next step in your work flow
总是会告诉您什么是未提交的,什么需要“添加”(暂存)以提交到您的本地存储库。事实上,git 会提示你它认为你工作流程的下一步是什么
(2) git add <your_file_path_you_can_use_glob_patternsLike_asteriks>
(3) git commit -m "A Nice Subject line for many file commits <enterFromKeyboardGivesYouAnotherLine>
(a) Continue typing more comments which are detailed if necessary <anotherEnterFromKeyboard>
(b) Some more details and do not forget to put closing quote mark"
Works in Windows if use the Windows git-bash.exe It uses mingW64 emulator to simulate linux environment. It's very good at it.
如果使用Windows git-bash.exe 可以在Windows 下工作 它使用mingW64 模拟器来模拟linux 环境。它非常擅长。
You need to commit whatever changes yout want to keep - locally before you can "push" your changes to your github repo remotely ie only after you have told git where your remote git repo is .....
您需要提交您想要保留的任何更改 - 在本地之前您可以远程“推送”您的更改到您的 github 存储库,即只有在您告诉 git 远程 git 存储库在哪里之后...
(4) git remote add myGitHubOrBitBucketRepo https://github.com/YourGitAppRepo.git
Usually the default name for your remote repo on github is given as "origin". But I have been using specific alias branch names which in your case is "myGitHubOrBitBucketRepo"
通常,您在 github 上的远程存储库的默认名称是“origin”。但是我一直在使用特定的别名分支名称,在您的情况下是“myGitHubOrBitBucketRepo”
(5) git push -u myGitHubOrBitBucketRepo HEAD:master
This command will push your committed changes (aka snap shots in git speak) to YourGitAppRepo.git on github.com onto the master branch and if master on your remote repo is not ahead of your local branch and it is just a couple of commits behind - github.com will accept this push
此命令会将您提交的更改(也就是 git speak 中的快照)推送到 github.com 上的 YourGitAppRepo.git 到 master 分支上,如果您的远程仓库上的 master 不在您的本地分支之前,并且它只是后面的几个提交- github.com 会接受这个推送
The -u is the same as --track which means that your local branch positioned @ HEAD will be tracking the master branch at your remote alias myGitHubOrBitBucketRep
-u 与 --track 相同,这意味着位于 @ HEAD 的本地分支将跟踪远程别名 myGitHubOrBitBucketRep 处的主分支
In steps 4 & 5 you will have to use a userId and passWord to interact with your remote repo on GitHub.com
在第 4 步和第 5 步中,您必须使用用户 ID 和密码与 GitHub.com 上的远程存储库进行交互
(6) git status
From now on git status will actually tell you whether you are behind or ahead of your remote github repo because of the --track (ing) option you had done in your push
从现在开始 git status 实际上会告诉你你是落后于还是领先于你的远程 github 仓库,因为你在推送中做了 --track (ing) 选项
Another useful command to use from this point onwards will be
从现在开始使用的另一个有用的命令是
git branch -vv --all
An example
一个例子
$ git branch -vv --all
* CurrAsOf18Jan2018 50d1fc6 [remotes/bitbucketFrmWin/master: behind 5] Pedantic but done - gitNotes.txt
remotes/bitbucketFrmWin/master 58470cd [CurrAsOf18Jan2018] This is really crazy - Spent more than a week - Singleton still gives
Over here bitbucketFrmWin is my alias for my remote bitbucket repo AsOf16Jan2018 is a branch that I am no longer interested master is my current main branch which I push my changes to from my local repo.
在这里,bitbucketFrmWin 是我远程 bitbucket 存储库的别名 AsOf16Jan2018 是一个我不再感兴趣的分支 master 是我当前的主分支,我将更改从本地存储库推送到它。
The --all option will also display your local & your "remotes"
--all 选项还将显示您的本地和您的“遥控器”
Of note is the following * CurrAsOf18Jan2018 50d1fc6 [remotes/bitbucketFrmWin/master: behind 5]
值得注意的是以下 * CurrAsOf18Jan2018 50d1fc6 [remotes/bitbucketFrmWin/master: 后面 5]
The asterik * that is the HEAD of my local branch or at which commit on that branch I am on. Usually it is always at the tip or the HEAD i.e. why it is called the "head"
星号 * 是我本地分支的 HEAD 或我所在分支的提交。通常它总是在尖端或头部,即为什么它被称为“头部”
CurrAsOf18Jan2018 is my local main branch and importantly it is saying that my local is already ahead of my remote branch by 5 commits - it is out of date so I need to update my remote with a "git push"
CurrAsOf18Jan2018 是我的本地主分支,重要的是它说我的本地分支已经领先于我的远程分支 5 次提交 - 它已经过时了所以我需要用“git push”更新我的远程分支
For now that is just one side of this story. If your remote repo goes ahead then another work-flow would be
目前这只是这个故事的一方面。如果您的远程仓库继续进行,那么另一个工作流程将是
git fetch --all && git merge --ff-only <theCommitYouWantYouToCatchUpWith>
That is altogether another post.
那完全是另一个帖子。
And here is a succinct image which I found courtesy Oliver Steele that displays another version of the basic git workflow life-cycle of versioning
这是我发现的一个简洁的图像,由 Oliver Steele 提供,它显示了版本控制的基本 git 工作流程生命周期的另一个版本
Hope this helps.
希望这可以帮助。
回答by Zin Myo Swe
git add .
git commit -m "my changes"
git remote add origin https://github.com/zinmyoswe/React-and-Django-Ecommerce.git
git push -u origin master