git 如何在 Github 中使用终端命令?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11019839/
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
How to use terminal commands with Github?
提问by iOS_Passion
I have forked a private repository (an iPhone project) as follows:
我已经分叉了一个私有存储库(一个 iPhone 项目),如下所示:
cd nameofdirectory
git init
git clone forkedURL
Now I want to push the changes done by me to my forked repository so that the main admin can review my written code and merge it with the main repository.
现在我想将我所做的更改推送到我的分叉存储库,以便主管理员可以查看我编写的代码并将其与主存储库合并。
How can I push the changes done by me to my forked repository using terminal on MacOS?
如何使用 MacOS 上的终端将我所做的更改推送到我的分叉存储库?
回答by Shahbaz
You can't push into other people's repositories. This is because push permanently gets code into their repository, which is not cool.
您不能推送到其他人的存储库。这是因为 push 永久地将代码放入他们的存储库中,这并不酷。
What you should do, is to ask themto pull from your repository. This is done in GitHub by going to the other repository and sending a "pull request".
您应该做的是要求他们从您的存储库中提取。这是在 GitHub 中通过转到另一个存储库并发送“拉取请求”来完成的。
There is a very informative article on the GitHub's help itself: https://help.github.com/articles/using-pull-requests
关于 GitHub 的帮助本身有一篇内容非常丰富的文章:https: //help.github.com/articles/using-pull-requests
To interact with your own repository, you have the following commands. I suggest you start reading on Git a bit more for these instructions (lots of materials online).
要与您自己的存储库交互,您可以使用以下命令。我建议您开始更多地阅读 Git 以了解这些说明(网上有很多资料)。
To add new files to the repository or add changed files to staged area:
要将新文件添加到存储库或将更改的文件添加到暂存区:
$ git add <files>
To commit them:
提交它们:
$ git commit
To commit unstaged but changed files:
要提交未暂存但已更改的文件:
$ git commit -a
To push to a repository (say origin
):
推送到存储库(例如origin
):
$ git push origin
To push only one of your branches (say master
):
只推送你的一个分支(比如master
):
$ git push origin master
To fetch the contents of another repository (say origin
):
获取另一个存储库的内容(比如origin
):
$ git fetch origin
To fetch only one of the branches (say master
):
只获取一个分支(比如master
):
$ git fetch origin master
To merge a branch with the current branch (say other_branch
):
将分支与当前分支合并(例如other_branch
):
$ git merge other_branch
Note that origin/master
is the name of the branch you fetched in the previous step from origin
. Therefore, updating your master branch from origin is done by:
请注意,这origin/master
是您在上一步中从 中获取的分支的名称origin
。因此,从源更新您的主分支是通过以下方式完成的:
$ git fetch origin master
$ git merge origin/master
You can read about all of these commands in their manual pages (either on your linux or online), or follow the GitHub helps:
您可以在他们的手册页(在您的 linux 上或在线)中阅读所有这些命令,或者遵循 GitHub 帮助:
- https://help.github.com/articles/create-a-repofor commit and push
- https://help.github.com/articles/fork-a-repofor fetch and merge
回答by Morgan
git add myfile.h
git commit -m "your commit message"
git push -u origin master
if you don't remember all the files you need to update, use
如果您不记得需要更新的所有文件,请使用
git status
回答by Swift Developer
To add all file at a time, use git add -A
要一次添加所有文件,请使用 git add -A
To check git whole status, use git log
要检查 git 整体状态,请使用 git log