git 我可以编辑两个文件,然后使用基于 Web 的 GitHub 编辑器进行一次提交吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17815895/
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
Can I edit two files then make one commit using GitHub Web-based editor?
提问by shengbinmeng
GitHub has the nice feature of Web-based file editing. However, it seems that after editing one file I have to commit the changes for this file before continuing. Is there a way I can edit two or more files then make one commit for all the changes of them?
GitHub 具有基于 Web 的文件编辑功能。但是,似乎在编辑一个文件后,我必须在继续之前提交对该文件的更改。有没有一种方法可以编辑两个或多个文件,然后对它们的所有更改进行一次提交?
I think this would be better since too many unnecessary commits are annoying.
我认为这会更好,因为太多不必要的提交很烦人。
采纳答案by Victor Istomin
There is a web-based workaround:
有一个基于 Web 的解决方法:
- Create a temporary branch, switch to it;
- Edit multiple files, commit each file separately;
- Make pull request;
- Merge pull request and delete temporary branch.
- 创建一个临时分支,切换到它;
- 编辑多个文件,分别提交每个文件;
- 发出拉取请求;
- 合并拉取请求并删除临时分支。
I use this method on a PC which I don't want to install git on.
我在不想安装 git 的 PC 上使用此方法。
回答by Mr-IDE
Yes there is a way, for when you've already edited your first file in the web browser view of GitHub. It's based on the instructions here:
是的,有一种方法,当您已经在 GitHub 的 Web 浏览器视图中编辑了您的第一个文件时。它基于此处的说明:
The summary and clarified steps are:
总结和澄清的步骤是:
- Edit your first file, by clicking the Edit icon in another user's repository. Save this edit in your first commit. GitHub will automatically create a new branch/fork for you, like "patch-1".
- Do not create a Pull Request yet.
- [This part is the most difficult, because it's not obvious]Go to the list of repositories in your profile, at
github.com ? click icon at top-right ? Your Repositories
. Then go to the forked repository that you've just made, and switch to the "patch-1" branch. - Continue making changes to another file, and commit it to your "patch-1" branch. When you are done, click "Create Pull Request". You should see your 2 commits in this Pull Request.
- If you don't see a "Create Pull Request" button, open a URL like this in your web browser:
https://github.com/TargetPerson/TargetGitRepo/compare/master...MyGithubUsername:patch-1
- This will show a view to compare your changes to the original target branch in the other user's repository. Then press the "Create Pull Request" button.
- 通过单击另一个用户的存储库中的“编辑”图标来编辑您的第一个文件。在您的第一次提交中保存此编辑。GitHub 会自动为你创建一个新的分支/分支,比如“patch-1”。
- 暂时不要创建拉取请求。
- [这部分是最困难的,因为它并不明显]转到您的个人资料中的存储库列表,位于
github.com ? click icon at top-right ? Your Repositories
. 然后转到您刚刚创建的分叉存储库,并切换到“patch-1”分支。 - 继续对另一个文件进行更改,并将其提交到您的“patch-1”分支。完成后,单击“创建拉取请求”。你应该在这个 Pull Request 中看到你的 2 个提交。
- 如果您没有看到“创建拉取请求”按钮,请在您的 Web 浏览器中打开这样的 URL:
https://github.com/TargetPerson/TargetGitRepo/compare/master...MyGithubUsername:patch-1
- 这将显示一个视图,用于将您的更改与其他用户存储库中的原始目标分支进行比较。然后按“创建拉取请求”按钮。
回答by davidqshull
Addendum to what @VictorIstominand @MarCnu were saying:
@VictorIstomin和 @MarCnu 所说的附录:
If you want to edit a number of filenames instead of the contents of those files, simply follow the instructions that Victor laid out, but you won't have to "Confirm Squash and Merge". You can just hit "Confirm Merge" (which should be the only option, since you didn't actually edit file contents.
如果您想编辑多个文件名而不是这些文件的内容,只需按照 Victor 列出的说明进行操作,但您不必“确认压缩和合并”。您只需点击“确认合并”(这应该是唯一的选项,因为您实际上并未编辑文件内容。
The question has been answered well, just wanted to clarify this for any future viewers who might be changing filenames, which is something I commonly do in GitHub.
这个问题已经得到了很好的回答,只是想为将来可能更改文件名的任何观众澄清这一点,这是我在 GitHub 中经常做的事情。
回答by Jordan McCullough
The GitHub Web Flow supports one file per commit. To add multiple files to a single commit, you will need to clone the repository locally, edit the files, then commit and push.
GitHub Web Flow 支持每次提交一个文件。要将多个文件添加到单个提交中,您需要在本地克隆存储库,编辑文件,然后提交和推送。
The command line would be like this:
命令行将是这样的:
cd
to the directoryStage all modified files with
git add <file-1> <file-2> <etc>
Commit with
git commit -m'<your-message>
or if you want to launch an external editor
git commit
Send the history/commit with
git push
cd
到目录暂存所有修改过的文件
git add <file-1> <file-2> <etc>
承诺
git commit -m'<your-message>
或者如果你想启动一个外部编辑器
git commit
发送历史/提交
git push
回答by Ilyich
Let's assume the repo in question is https://github.com/repoUsername/repoName
让我们假设有问题的 repo 是https://github.com/repoUsername/repoName
- Fork the repository by clicking the
Fork
button at the top of the repo page.
- 通过单击存储库
Fork
页面顶部的按钮分叉存储库。
Edit as many files as you want via Web-based file editor in your fork of the repo. Commit each file individually.
Go to https://github.com/repoUsername/repoName/pullsand press the big green
New pull request
button.
通过基于 Web 的文件编辑器在您的 repo 分支中编辑任意数量的文件。单独提交每个文件。
转到https://github.com/repoUsername/repoName/pulls并按下绿色大
New pull request
按钮。
- On the next page click
compare across forks
link.
- 在下一页上单击
compare across forks
链接。
- Then in
Choose a Head Repository
field select your fork
- 然后在
Choose a Head Repository
现场选择你的叉子
Create pull request
button will appear. Click it.
Create pull request
按钮将出现。点击它。
- Enter title and description of your pull request and click
Create pull request
button again.
- 输入拉取请求的标题和描述,然后
Create pull request
再次单击按钮。