拜托了

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來同時fetchmerge 。 我沒有遇到需要手動fetchmerge任何實例,因此我無法對這些情況進行討論。 使用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/

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/395620.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/395620.shtml
英文地址,請注明出處:http://en.pswp.cn/news/395620.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

性能測試類型

1.驗收性能測試 驗收性能測試(Acceptance Performance Testing)方法通過模擬生產運行的業務壓力量和使用場景組合,測試系統的性能是否滿足生產性的要求。通俗的說:在特定的運行條件下驗證系統的能力狀況。 (1&#xff…

Java - 對象(object) 具體解釋

對象(object) 具體解釋 本文地址: http://blog.csdn.net/caroline_wendy/article/details/24059545 對象(object)的實例能夠是 物理對象(如 人, 車等實物) 或 邏輯對象(如 運動, 健康等); 對象是將狀態(數據) 和行為(功能) 組合在一起的軟件模塊. 類是描寫敘述一組相似對象共同…

kkt條件的matlab仿真,請教關于SVM中KKT條件的推導

KKT條件第一項是說最優點必須滿足所有等式及不等式限制條件,也就是說最優點必須是一個可行解,這一點自然是毋庸置疑的。第二項表明在最優點 x*, ?f 必須是 ?hj 和 ?gk 的線性組合,和都叫作拉格朗日乘子。所不同的是不等式限制條…

公共wifi做家用_如何在公共網絡上獲得免費的wifi

公共wifi做家用by Kyle McDonald凱爾麥克唐納(Kyle McDonald) 如何在公共網絡上獲得免費的wifi (How to get free wifi on public networks) This short tutorial describes a few methods for gaining access to the internet, a basic human right, from public wireless ne…

python學習之旅

一、入門 1.Python 面向對象編程 2.jquery入門 3.HTMLCSS基礎入門 4.Javascript初步 5.Python語言編程基礎 二、初級階段 1.Git 與 GitHub 2.Python 爬蟲基礎 3.django進階 4.django項目部署 5.ajax入門 6.django基礎 7.Mysql基礎 三、中級階段 1.Linux基礎 2.Python :socket a…

c/c++ 重載運算符 函數調用運算符

重載運算符 函數調用運算符 把一個類的對象a,當成函數來使用,比如a(),所以需要重載operator()方法。重載了函數調用運算符的類的對象,就是函數對象了。 還有什么是函數對象呢??? lambda是函數對…

matlab 萬能,matlab 萬能實用的線性曲線擬合方法

在科學計算和工程應用中,經常會遇到需要擬合一系列的離散數據,最近找了很多相關的文章方法,在這里進行總結一下其中最完整、幾乎能解決所有離散參數線性擬合的方法第一步:得到散點數據根據你的實際問題得到一系列的散點例如&#…

socket websocket

1.websocket客戶端 websocket允許通過JavaScript建立與遠程服務器的連接,從而實現客戶端與服務器間雙向的通信。在websocket中有兩個方法:      1、send() 向遠程服務器發送數據    2、close() 關閉該websocket鏈接  websocket同時還定義了幾…

javascript原型_JavaScript的原型:古怪,但這是它的工作原理

javascript原型by Pranav Jindal通過普拉納夫金達爾 JavaScript的原型:古怪,但這是它的工作原理 (Prototype in JavaScript: it’s quirky, but here’s how it works) The following four lines are enough to confuse most JavaScript developers:以下…

mysql函數之SUBSTRING_INDEX(str,/,-1)

SUBSTRING_INDEX的用法: ?SUBSTRING_INDEX(str,delim,count) 在定界符 delim 以及count 出現前,從字符串str返回自字符串。若count為正值,則返回最終定界符(從左邊開始) 若為-1則是從后往前截取 SELECT substring_index(Hn_P00001, P, -1) -- 結果是…

mysql8.0主從配置,MySQL 8.0主從服務器(Master-Slave)配置

一、介紹MySQL 主從復制的方式有多種,本文主要演示基于基于日志(binlog)的主從復制方式。MySQL 主從復制(也稱 A/B 復制) 的原理:Master將數據改變記錄到二進制日志(binary log)中,也就是配置文件log-bin指定的文件, 這些記錄叫做…

第十二章 Shell腳本編寫及常見面試題(三)

本章目錄&#xff1a;12.21 FTP下載文件#!/bin/bash if [ $# -ne 1 ]; thenecho "Usage: $0 filename" fi dir$(dirname $1) file$(basename $1) ftp -n -v << EOF # -n 自動登錄 open 192.168.1.10 user admin adminpass binary # 設置ftp傳輸模式為二進制…

亞馬遜面試有幾輪_經過幾個月的Google面試準備,我被亞馬遜錄用

亞馬遜面試有幾輪by Googley as Heck由Googley飾演Heck 經過幾個月的Google面試準備&#xff0c;我被亞馬遜錄用 (After months of preparing for the Google interview, I got hired by Amazon) As you may know, the last 11 months have been very difficult for me. As a …

省選前的考試記錄

日拱一卒功不唐捐 什么沙雕玩意兒 2018.12.24 T1 如果對 \(A\) 數組求出來高度遞減的單調棧的話&#xff0c;會發現只有單調棧里的元素是有用的。因為如果有 \(A[i]<A[j] \And i<j\)&#xff0c;那電梯就可以在帶 \(j\) 上樓的時候順便把 \(i\) 帶上并不會影響結果。所以…

軟件工程課設-----日程管理系統

這學期進行了軟件工程課設&#xff0c;題目是&#xff1a;日程管理系統&#xff08;JavaWeb&#xff09;&#xff0c;為期3周。這三周只有前兩天是企業老師講解是企業老師講解相關的基礎知識(老師講的水平實在是不可恭維。。。。。。)。 多的不多說。直接進行對相關項目的介紹。…

matlab中的神經網絡訓練,MATLAB中的神經網絡訓練

我試圖向前饋送反向傳播&#xff0c;但是在網絡訓練之后&#xff0c;當模擬和打印模擬輸出時&#xff0c;我看不到任何靠近目標的值&#xff0c;但它只是一個數字。代碼如下。什么是錯&#xff0c;什么是問題&#xff1f;前饋反向傳播&#xff1a;>> load(E:/Inputdata.t…

Spring For All 頂級Spring綜合社區服務平臺

Spring For All 玩最純粹的技術&#xff01;做最專業的 Spring 民間組織~ 歡迎加入&#xff1a;http://spring4all.com/ image.png

chromium 桌面_如何使用Chromium和PyInstaller將Web應用程序轉換為桌面應用程序

chromium 桌面Packaging and distributing your app sounds simple in principle. It’s just software. But in practice, it’s quite challenging.打包和分發應用程序在原理上聽起來很簡單。 這只是軟件。 但是在實踐中&#xff0c;這非常具有挑戰性。 I’ve been working …

PHP面向對象(三)

一、繼承概念 繼承性也是面向對象程序設計中的重要特性之一。它是指建立一個新的派生類&#xff0c;從一個先前定義的類中繼承數據和函數&#xff0c;而且可以重新定義新的數據類型和函數&#xff0c;從而建立累的層次或等級關系。 格式&#xff1a;     [修飾符] class 子…