git 别名:使用参数提交推入单个命令

发布于 2024-11-17 15:20:18 字数 324 浏览 3 评论 0原文

我试图说服我的同事离开 svn 并切换到 git。我看到的一个问题是:必须分别执行 git commit 和 git push 很复杂且容易出错。所以我正在考虑 git ci 别名,它提交更改并将其直接推送到服务器。我知道该怎么做,但是:

问题是,我想给 git commit 提供像 -m "" 这样的参数。那么

git ci -m "Cool change"

应该执行

git commit -m "Cool change" && git push

我该怎么做?

I try to convince my coworkers to leave svn and switch to git. One problem I see coming is: It's complicated and error-prone to have to do git commit and git push separately. So I was thinking about a git ci alias, which commits the changes and pushes it right to the server. I know, how to do that, but:

The problem is, that I want to give arguments like -m "" to git commit. So

git ci -m "Cool change"

should execute

git commit -m "Cool change" && git push

How can I do so?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不必在意 2024-11-24 15:20:19

你可以像“git Achievement”项目一样“隐藏”git。这将使您能够添加类似于 git 命令的脚本。您的基本流程应该是:

git pull --rebase

以便历史记录像 SVN 更新中所习惯的那样呈线性。但你必须告诉他们,他们可能需要消除冲突,并告诉他们或别名 git add -A && 。 git rebase --继续。我建议打开 rerere 并在整个团队中共享这些解决方案,并在您要为此创建的“别名”上附加一个脚本。

接下来,用这样的东西隐藏提交:

git add -A
git commit -m "message"
git pull --rebase
git push origin <current branch> # or set up tracking and omit the last 2 args

这些也应该在冲突时优雅地失败。

这里是 git 成就的链接:

http://benjamin-meyer.blogspot .com/2010/03/git-achievements.html

虽然我认为从长远来看这对他们没有帮助,但我希望这对现在有帮助。

you can "hide" git much like the "git achievement" project does. This will enable you to add scripts that look like git commands. Your basic flow should be:

git pull --rebase

so that history is linear like what they are used to in SVN's update. But you must tell them that they may need to get rid of conflicts and tell them about or alias git add -A && git rebase --continue. I suggest turning on rerere and sharing those resolutions across the team with a script attached to the "alias" you're going to make for this.

Next, hide commit with something like this:

git add -A
git commit -m "message"
git pull --rebase
git push origin <current branch> # or set up tracking and omit the last 2 args

These should fail gracefully on conflicts as well.

here is the link to git achievements:

http://benjamin-meyer.blogspot.com/2010/03/git-achievements.html

Although I think this is not helping them in the long run, I hope this helps for now.

成熟的代价 2024-11-24 15:20:19

对于将参数作为别名添加到多个命令之一的一般问题,git 别名的工作方式几乎与普通的 *nix 别名完全相同。唯一的区别是,除非 git 别名以 ! 开头,否则假定应将 git 添加到命令前面。任何与别名结合使用的参数都会被添加到前面,要将参数插入命令记录器字符串中,您需要某种 shell 命令来解析参数。例如,请参阅这个问题 用于参数。

但特别针对这个问题。我同意其他人的观点,认为这是一件有用的事情。如果你要在提交后立即推送,我假设每个用户都有自己的公共私有存储库(对其他人来说只读),这样推送将“永远”失败,这意味着它的工作方式与 svn 无论如何都非常不同;他们必须从不同的存储库等中拉取。

如果您使用每个人都拉取和推送的公共“主存储库”,这将是一个更糟糕的想法,因为当推送有时不可避免地会失败时,他们被训练不要这样做使用“commit”然后“push”,但使用“ci”别名来提交和推送更改;当他们尝试“重新提交”更改时,第二部分将不会运行,因为第一个命令未以成功状态完成(但打印没有添加到提交的更改(使用“git add”和/或“git commit”) -a") 代替)。

For the general problem of adding arguments to one of multiple commands as an alias, the git alias works almost exactly like a normal *nix alias. The only difference it that unless the git alias starts with ! it's assumed that git should be prepended to the command. Any arguments used in combination with an alias is prepended, to insert an argument into a loger string of commands you need some kind of shell command for parsing the arguments. See for instance this question for arguments.

But for this question in particular. I agree with the others that this is a useful thing to do. If you're going to push immediately after committing, I assume each user have their own public private repo (readonly for others) so that the push will "never" fail, which means it works very different from svn anyway; they must pull from different repos etc.

If you're instead are using one public "master repo" that everyone pulls and pushes to, this would be a even worse idea, since when the push inevitably will fail sometime, they are trained not to use "commit" then "push" but use your "ci" alias to commit and push changes; When they try to "re-commit" the changes the second part will not run because the first command does not finish with success status (but prints no changes added to commit (use "git add" and/or "git commit -a") instead).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文