亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何告訴git忽略個別行,即gitignore用于特定代碼行

如何告訴git忽略個別行,即gitignore用于特定代碼行

Git
呼啦一陣風 2019-11-22 15:07:18
.gitignore 可以忽略整個文件,但是有沒有辦法在編碼時忽略特定的代碼行?我經常重復地在項目中添加相同的調試行,只是要記住在提交之前將其刪除。我只想將行保留在代碼中,并讓git忽略它們。
查看完整描述

3 回答

?
米脂

TA貢獻1836條經驗 獲得超3個贊

我在編寫Java代碼時遇到了類似的問題。我的解決方案是標記不想提交的代碼,然后添加一個預提交的鉤子來尋找我的標記:


#!/bin/bash

#

# This hook will look for code comments marked '//no-commit'

#    - case-insensitive

#    - dash is optional

#    - there may be a space after the //

#

noCommitCount=$(git diff --no-ext-diff --cached | egrep -i --count "(@No|\/\/\s?no[ -]?)commit")

if [ "$noCommitCount" -ne "0" ]; then

   echo "WARNING: You are attempting to commit changes which include a 'no-commit'."

   echo "Please check the following files:"

   git diff --no-ext-diff --cached --name-only -i -G"(@no|\/\/s?no-?)commit" | sed 's/^/   - /'

   echo

   echo "You can ignore this warning by running the commit command with '--no-verify'"

   exit 1

fi


查看完整回答
反對 回復 2019-11-22
?
幕布斯7119047

TA貢獻1794條經驗 獲得超8個贊

這是有趣的。但這基本上就像問題線不存在一樣。對于像只是簡單地更改一行更改之類的操作,它是行不通的。因此,例如,您不能在函數調用中更改變量的值。例如,您不必確保將其更改flags = foo | barflags = foo | bar | debug_thingy,而是必須添加一個像flags |= debug_thingyafter之后的全新行。

查看完整回答
反對 回復 2019-11-22
  • 3 回答
  • 0 關注
  • 710 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號