日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

拜托了

發布時間:2023/11/29 编程问答 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 拜托了 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

by Buddy Reno

由Buddy Reno

Git Please :如何在不做蠢事的情況下強行推動 (Git Please: how to force push without being a jerk)

As the size of a dev team grows, so does the likelihood of someone doing a force push and overwriting someone else’s code.

隨著開發團隊規模的擴大,有人進行強制推送并覆蓋他人代碼的可能性也在增加。

Here’s what a force push looks like in Git:

這是在Git中的強制推送的樣子:

$ git push --force origin master# `--force` can also be written as `-f`

This command can cause all kinds of problems. It basically tells Git that I don’t care what is in origin/master. What I have is correct. Overwrite it.

此命令可能會導致各種問題。 它基本上告訴Git 我不在乎源/母版是什么。 我所擁有的是正確的。 覆蓋它。

So what happens if a co-worker had changes committed to a branch that you haven’t pulled down into your own repo? It gets overwritten, and your co-worker potentially has to re-do their work (or resurrect a commit or two if they still have it locally).

那么,如果同事將更改提交到您尚未拉入自己的存儲庫的分支中,該怎么辦? 它會被覆蓋,您的同事可能必須重新做他們的工作(或者如果他們本地仍然有一個提交,則復活一兩個提交)。

But this whole mess can be easily avoided with a small change to how you use theforceflag. Instead of using —-force, Use --force-with-lease.

但是,只需對使用force flag的方式進行少量更改,就可以輕松避免整個混亂情況。 而不是使用—-force ,而是使用--force-with-lease 。

$ git push --force-with-lease origin master

To summarize Git’s documentation, using force-with-lease tells git to check whether the remote repo is the same as the one you’re trying to push up. If it isn’t, git will throw an error instead of blindly overwriting the remote repo. This will save you from accidentally overwriting work that you don’t intend to.

總結一下Git的文檔 ,使用force-with-lease告訴git檢查遠程倉庫是否與您要推送的倉庫相同。 如果不是,git會拋出一個錯誤,而不是盲目地覆蓋遠程倉庫。 這樣可以避免意外覆蓋您不想要的工作。

I hate typing force-with-lease though — especially because I’m used to typing the shorthand -f for force pushing. Thankfully, Git allows you to add aliases to make this quicker. I like to think that I’m asking Git if it’s okay to force push, so I’ve aliased push —force-with-lease to git please.

我不喜歡鍵入force-with-lease —尤其是因為我習慣于鍵入簡寫-f進行強制推送。 幸運的是,Git允許您添加別名以使其更快。 我想以為我是在問Git是否可以強制執行推送,因此我push —force-with-lease別名為git please 。

$ git please origin master

You can add an alias in git by typing this into your terminal:

您可以通過在終端中輸入以下別名在git中添加別名:

git config --global alias.please 'push --force-with-lease'

Or you can open up your ~/.gitconfig file and manually add the alias:

或者,您可以打開~/.gitconfig文件并手動添加別名:

[alias] co = checkout ci = commit please = push --force-with-lease

總是有一個警告... (There’s always a caveat…)

It’s possible to trick force with lease however. When you use git pull to get updates from the origin, this is doing two commands at once. Git runs a fetch to pull down the reference to all the changes. Then it runs a merge to merge the changes you just fetched into your current branch.

但是,可以通過租賃來欺騙力量。 當您使用git pull從源獲取更新時,這會同時執行兩個命令。 Git運行fetch以拉低所有更改的引用。 然后,它運行merge以將您剛獲取的更改merge到當前分支中。

If you only do a fetch to get the latest updates, you’ll only be updating your references — not actually merging the changes into your working copy. Then, if you force push with lease, Git will look at those references and think that the local copy is up to date with the remote, when in reality it isn’t yet. This will trick Git into overwriting the changes on the remote with your local copy, without having the changes actually merged in.

如果您僅fetch最新的更新,則只會更新參考文獻,而實際上并未將更改合并到工作副本中。 然后,如果您強制使用租用推送,則Git將查看這些引用,并認為本地副本與遠程設備是最新的,而實際上還不是。 這將使Git欺騙您使用本地副本覆蓋遠程上的更改,而無需真正合并更改。

The easiest way to avoid this problem is always use git pull to fetch and merge at the same time. I’ve not run into any instances where I’ve needed to fetch and merge manually, so I can’t speak to those circumstances. Using pull has always worked for me.

避免此問題的最簡單方法是始終使用git pull來同時fetch和merge 。 我沒有遇到需要手動fetch和merge任何實例,因此我無法對這些情況進行討論。 使用pull一直對我有用。

I hope you find git please helpful and that, as a result, you never have to recover from a force-push nightmare.

我希望您對git please有所幫助,因此,您不必從強行噩夢中恢復過來。

翻譯自: https://www.freecodecamp.org/news/git-please-a182f28efeb5/

總結

以上是生活随笔為你收集整理的拜托了的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。