जैसा कि मेरे अन्य उत्तर द्वारा सुझाया गया है, यहां समाधान के विस्तारित, सामान्यीकृत, औद्योगिक-शक्ति संस्करण को चलाया गया है।
(हाँ, मैं घर पर ऊब और ऐसा करने के लिए बेहतर और कुछ नहीं था: पी), तो यह एक नया, अलग अपने स्थानीय डिजाइन शाखा के आधार पर प्रतिबद्ध
यह स्क्रिप्ट जोड़ देगा न तो डिजाइन भंडार या आपकी डिजाइन शाखा को प्रभावित करेगा। प्रतिबद्धता में सभी वांछित फाइलें हटा दी जाएंगी। फिर यह विलय करता है।
भी भरा कोड, निम्न चरणों का "मूल" पढ़ने के लिए आलसी उन लोगों के लिए के रूप में सरल किया जा सकता:
original=$(gitbranch HEAD) # current branch name, or sha1 if not in a branch
branchsha=$(gitsha "$branch") # sha1 of a ref, to force detached commit
git checkout "$branchsha" &&
git rm -rf "${files[@]}" &&
git commit -m "$msgcommit" &&
newsha=$(gitsha HEAD) &&
git checkout "$original" &&
git merge -m "$msgmerge" "${mergeopts[@]}" "$newsha"
और यहाँ पूर्ण स्क्रिप्ट है:
(थोड़ा करने के लिए संशोधित कमजोर और सीमित तो चलो वाक्य रचना रंग से निपटने, तो यह बेहतर है नीचे दिए गए लिंक से प्राचीन स्रोत प्राप्त करने के लिए)
git-strip-merge
#!/bin/bash
#
# git-strip-merge - a git-merge that delete files on branch before merging
#
# Copyright (C) 2012 Rodrigo Silva (MestreLion) <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not see <http://www.gnu.org/licenses/gpl.html>
#
# Answer for "How to setup a git driver to ignore a folder on merge?"
# See http://stackoverflow.com/questions/3111515
#Defaults:
msgcommit="remove files from '<branch>' before merge"
msgmerge="Merge stripped branch '<branch>'"
verbose=0
quiet=(--quiet)
usage() {
cat <<- USAGE
Usage: $myname [git-merge options] [-M <commitmsg>] <branch> FILE...
USAGE
if [[ "$1" ]] ; then
cat >&2 <<- USAGE
Try '$myname --help' for more information.
USAGE
exit 1
fi
cat <<-USAGE
"git-merge that delete files on "foreign" <branch> before merging
Useful for ignoring a folder in <branch> before merging it with
current branch. Works by deleting FILE(S) in a detached commit based
on <branch>, and then performing the merge of this new commit in the
current branch. Note that <branch> is not changed by this procedure.
Also note that <branch> may actually be any reference, like a tag,
or a remote branch, or even a commit SHA.
For more information, see <http://stackoverflow.com/questions/3111515>
Options:
-h, --help
show this page.
-v, --verbose
do not use -q to supress normal output of internal steps from git
checkout, rm, commit. By default, only git merge output is shown.
Errors, however, are never supressed
-M <message>, --msgcommit=<message>
message for the removal commit in <branch>. Not to be confused
with the message of the merge commit, which is set by -m. Default
message is: "$msgcommit"
-m <message>, --message=<message>
message for the merge commit. Since we are not merging <branch>
directly, but rather a detached commit based on it, we forge a
message similar to git's default for a branch merge. Otherwise
git would use in message the full and ugly SHA1 of our commit.
Default message is: "$msgmerge"
For both commit messages, the token "<branch>" is replaced for the
actual <branch> name.
Additional options are passed unchecked to git merge.
All options must precede <branch> and FILE(s), except -h and --help
that may appear anywhere on the command line.
Example:
$myname design "photoshop/*"
Copyright (C) 2012 Rodrigo Silva (MestreLion) <[email protected]>
License: GPLv3 or later. See <http://www.gnu.org/licenses/gpl.html>"
USAGE
exit 0
}
# Helper functions
myname="${0##*/}"
argerr() { printf "%s: %s\n" "${0##*/}" "${1:-error}" >&2 ; usage 1 ; }
invalid() { argerr "invalid option: $1" ; }
missing() { argerr "missing ${2:+$2 }operand${1:+ from $1}." ; }
# Option handling
files=()
mergeopts=()
for arg in "[email protected]"; do case "$arg" in -h|--help) usage ;; esac; done
while (($#)); do
case "$1" in
-v|--verbose ) verbose=1 ;;
-M ) shift ; msgcommit=$1 ;;
-m ) shift ; msgmerge=$1 ;;
--msgcommit=*) msgcommit=${1#*=} ;;
--message=* ) msgmerge=${1#*=} ;;
-* ) mergeopts+=("$1") ;;
* ) branch="$1"
shift ; break ;;
esac
shift
done
files+=("[email protected]")
# Argument handling
msgcommit=${msgcommit//<branch>/$branch}
msgmerge=${msgmerge//<branch>/$branch}
[[ "$msgcommit" ]] || missing "msgcommit" "MSG"
[[ "$branch" ]] || missing "" "<branch>"
((${#files[@]})) || missing "" "FILE"
((verbose)) && quiet=()
# Here the fun begins...
gitsha() { git rev-parse "$1" ; }
gitbranch() {
git symbolic-ref "$1" 2> /dev/null | sed 's/refs\/heads\///' ||
gitsha "$1"
}
original=$(gitbranch HEAD)
branchsha=$(gitsha "$branch")
trap 'git checkout --quiet "$original"' EXIT
git checkout "$branchsha" "${quiet[@]}" &&
git rm -rf "${files[@]}" "${quiet[@]}" &&
git commit -m "$msgcommit" "${quiet[@]}" &&
newsha=$(gitsha HEAD) &&
git checkout "$original" "${quiet[@]}" &&
git merge -m "$msgmerge" "${mergeopts[@]}" "$newsha"
आनंद लें!
एक छवि एक हजार से अधिक शब्दों के लायक है ...
मर्ज से पहले:
ध्यान दें कि "डिजाइन" शाखा टिप बिल्कुल प्रभावित नहीं था, यहां तक कि एक स्थानीय शाखा जा रहा है, धन्यवाद करने के लिए:
मर्ज करने के बाद अलग प्रतिबद्ध चाल। इसके अलावा, उपयुक्त प्रतिबद्ध संदेश और माता-पिता दोनों के साथ काम करता है (हटाने और विलय) नियमित रूप से काम करता है। और "मास्टर" शाखा किसी भी अवांछित फ़ाइलों की सफाई है।
संभावित डुप्लिकेट [मैं एक विशिष्ट फ़ाइल पर विवादित विलय के लिए हमेशा अपने स्थानीय संस्करण का चयन करने के लिए गिट कैसे कहूं?] (Http://stackoverflow.com/questions/928646/how-do-i-tell-git- हमेशा-चयन-मेरे-स्थानीय-संस्करण-के लिए विवादित-विलय-ऑन-ए) – givanse