git 如何在 gitlab 中创建和提交分支
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32125514/
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 create and commit a branch in gitlab
提问by puk
This is intended as a question that I answer for other people's benefit. However, if someone answers this question before I finish my research, I would be grateful.
这是我为了其他人的利益而回答的问题。但是,如果有人在我完成研究之前回答了这个问题,我将不胜感激。
How do I, from the shell, branch an existing git repo (which I have developer access to), edit it, commit those changes then pushit to the server for review before being merged.
我如何从 shell 分支现有的 git repo(我有开发人员访问权限),编辑它,提交这些更改,然后在合并之前将其推送到服务器进行。
EDIT
编辑
Please note that this is not my project, but someone else's. This use has given me access to do some work. When done, I will request that they merge the changes back to the original
请注意,这不是我的项目,而是其他人的项目。这种使用使我可以做一些工作。完成后,我会要求他们将更改合并回原始版本
回答by Sari Rahal
For setting up your repo, you will need to follow these instructions. Then you will need to clone/fork the existing repo like this.
要设置您的存储库,您需要按照这些说明进行操作。然后你需要像这样克隆/分叉现有的仓库。
Then make your changes. Once you are done making your changes. You will need to make a "commit" that looks like this
然后进行更改。完成更改后。您将需要进行如下所示的“提交”
git commit -m "I changed something somewhere"
Then you will want to pull down any changes from the repo that may have been pushed while you were working.
然后,您将希望从存储库中提取在您工作时可能已推送的任何更改。
git pull origin master // master being the branch that you cloned/forked
Once the pull is completed with no conflicts, you may push your changes up.
拉动完成且没有冲突后,您可以将更改推高。
git push origin master // this is saying that you want to replace the remote master branch with your local master branch
EDITTo push to a repo without overwriting the master, do this:
编辑要在不覆盖 master 的情况下推送到 repo,请执行以下操作:
git clone //clone what branch you want
git checkout -b new_branch //this will create a new local branch
git push origin new_branch //this will create a new origin branch
回答by janos
If I understand your question correctly:
如果我正确理解你的问题:
- You don't have permission to push to the repository
- You want to create a branch, make some commits, and then propose a merge request
- 您无权推送到存储库
- 你想创建一个分支,做一些提交,然后提出一个合并请求
This is actually a perfectly normal situation, here's what to do:
这实际上是一种完全正常的情况,以下是该怎么做:
On GitLab, fork the project: this creates a clone of the original repository in your personal workspace. The point is that you can push to your personal workspace.
On your PC, clone from your fork, not the original.
Create a branch (
git checkout -b myfeature
), make the changes and commit, then push this branch to your fork (git push -u origin HEAD
)On GitLab, visit your fork's page, and near the top there should be a button offering you to create a Merge Request from the branch that you pushed just now. Click on it, review the changes, if it looks good, then set an assignee and click Create. The assignee should receive an email notification
在 GitLab 上,fork 项目:这会在您的个人工作区中创建原始存储库的克隆。关键是您可以推送到您的个人工作区。
在您的 PC 上,从您的 fork 克隆,而不是原始克隆。
创建一个分支 (
git checkout -b myfeature
),进行更改并提交,然后将此分支推送到您的 fork (git push -u origin HEAD
)在 GitLab 上,访问您的 fork 页面,在顶部附近应该有一个按钮,让您可以从您刚刚推送的分支创建合并请求。单击它,查看更改,如果看起来不错,然后设置受让人并单击创建。受让人应收到电子邮件通知
You don't need write access to a project to be able to contribute.
All your write operations are on your workspace on GitLab and on your local PC.
Reviewers of your Merge Request can accept it or reject as they wish.
They can also ask that you make improvements, which you can implement and push (simple git push
after your local commits), that updates the merge request (reviewers can reload the page in the browser and see your changes).
您不需要对项目的写访问权限即可做出贡献。你所有的写操作都在你的 GitLab 工作区和本地 PC 上。您的合并请求的审阅者可以根据需要接受或拒绝。他们还可以要求您进行改进,您可以实施和推送(git push
在本地提交后很简单),更新合并请求(审阅者可以在浏览器中重新加载页面并查看您的更改)。