2017-03-08 5 views
5

मैं कई अलग-अलग गिट शाखाओं का उपयोग कर एक बड़ी सी ++ परियोजना पर काम कर रहा हूं। हम गिट फ्लो मॉडल का उपयोग कर रहे हैं। इसका मतलब है कि मैं नियमित रूप से गिट शाखाओं के बीच स्विच करता हूं। मैं कोड को नेविगेट करने के लिए Emacs में हेल्म-gtags का उपयोग करता हूं। फिलहाल मैंने गिट संस्करण नियंत्रण के तहत जीएनयू ग्लोबल टैग फाइलों (जीएजीएस, जीआरएजीएस, जीपीएटीएच) को नहीं रखा है, जब भी मैं एक अलग शाखा पर काम करने के लिए बदल जाता हूं तो वे बस रहते हैं। लेकिन इसका मतलब यह हो सकता है कि मेरे पास टैग फ़ाइलों में प्रतीक हैं जो कोड में मौजूद नहीं हैं, और इसके विपरीत। मैं टैग फ़ाइलों को अद्यतन कर सकता हूं (हेल्म-gtags-update-tag) लेकिन यह कोड फ़ाइलों में मौजूद टैग फ़ाइलों से प्रतीकों को नहीं हटाता है, यह केवल कोड में मौजूद प्रतीकों को जोड़ता या अपडेट करता है।विभिन्न गिट शाखाओं में जीएनयू ग्लोबल टैग फाइलों का सही उपयोग

जीएनयू ग्लोबल टैग फाइलों के साथ काम करने का सबसे अच्छा तरीका क्या है जो गिट द्वारा नियंत्रित संस्करण है? टैग टैग को गिट में जोड़ा जाना चाहिए ताकि वे प्रत्येक शाखा के लिए विशिष्ट हों? या जब भी मैं टैग का ताजा सेट उत्पन्न करने के लिए शाखा स्विच करता हूं तो क्या मुझे टैग फ़ाइलों को हटा देना चाहिए? क्या कोई और तरीका है?

+0

मैं सहमत हूं, आगे बढ़ें और माइग्रेट करें। –

+0

'git/hooks/post-checkout में' global -u' रखें। – politza

+0

@ पोलिट्ज़ा "ग्लोबल-यू 'की समस्या के साथ सौदा करता है" कोड में मौजूद टैग फ़ाइलों से प्रतीकों को नहीं हटाता है, यह केवल कोड में मौजूद प्रतीकों को जोड़ता या अपडेट करता है "? मैं केवल कल्पना कर सकता हूं कि 'हेल्म-gtags-update-tag'' global -u 'को कॉल कर रहा है, ऐसा लगता है कि यह अपर्याप्त हो सकता है। यदि यह सब कुछ आवश्यक है, हालांकि, और यह सभी बदली गई फ़ाइलों को नोटिस करने के लिए पर्याप्त स्मार्ट है, तो मैं सहमत होगा कि यह स्पष्ट रूप से सबसे सरल समाधान है। – phils

उत्तर

0

के बाद से टैग फ़ाइलें कोड की एक विशेष संस्करण के साथ जुड़े रहे हैं, मेरा मानना ​​है कि आप में उन्हें जांच होनी चाहिए।

दूसरी ओर, वे कर रहे हैं कोड के साथ काम करने की विशेष में किसी एक प्रकार फाइलें, और इसलिए आम तौर पर परियोजना पर लागू नहीं होता है, और इसलिए यह तर्क दिया जा सकता है कि इसे चेक नहीं किया जाना चाहिए। वे लगातार बदल रहे होंगे और प्रत्येक प्रतिबद्धता के लिए बहुत शोर जोड़ देंगे। शोर कि हर किसी को देखना है।

इसके बजाय मैं सुझाव देता हूं कि इमाक्स को कॉन्फ़िगर करने के लिए यह देखना है ताकि जब वे बदल जाए तो स्वचालित रूप से फ़ाइलों के अपने दृश्य को स्वचालित रूप से अपडेट कर दें। यह वही है जो अधिकांश आधुनिक संपादक करते हैं। Here's a technique using inotify। या, और मुझे पता है कि यह पाखंडी है, यह एक नए संपादक के लिए समय हो सकता है। मैंने इस वर्ष emacs से Atom पर स्विच किया।

0

उन्हें प्रतिबद्ध करना सबसे अच्छा विचार प्रतीत नहीं होता है, और यह निर्भर करता है कि ग्लोबल के लिए आपकी पूरी परियोजना को फिर से चलाने के लिए कितना समय लगता है, आप इसे हर बार शाखाओं को बदलने के दौरान पूरे डेटाबेस को पुनर्निर्माण के लिए अवांछनीय पाते हैं।

यदि कोई पूर्ण पुनर्निर्माण बहुत लंबा लगता है, तो यहां post-checkout गिट हुक है जिसे मैंने प्रति शाखा आधार पर अनचाहे फ़ाइलों को प्रबंधित करने के लिए लिखा था।

प्रत्येक शाखा के लिए आप अपनी जीएजीएस, जीआरएजीएस, जीपीएटीएच फाइलों को इस स्क्रिप्ट द्वारा उपयोग की जाने वाली .branches निर्देशिका की एक उचित नाम वाली उप-निर्देशिका में कॉपी करेंगे, और तब जब भी आप शाखाएं बदलते हैं तो स्क्रिप्ट फाइलों को स्वैप कर देगी।

#!/bin/sh 

# Git hook (post-checkout) to manage *untracked* files on a per-branch basis. 
# Author: Phil S. 
# Version 1.1 
# URL: http://stackoverflow.com/a/42686433 

## Commentary: 
# 
# This hook is very useful when you have development-specific files which 
# you never want to commit to the repository, but which can vary on a 
# branch-by-branch basis. Branch-specific configuration files are a 
# prime use-case (to specify the database to use, for instance). 
# 
# With this hook, those files are automatically copied into the working 
# copy when you checkout the branch they are associated with, and moved 
# back again when you checkout another branch. 
# 
# The hook uses a .branches directory in the root of the repository, 
# so you should add this to your .gitignore file. 
# 
# To start managing files for a branch, simply copy them into a sub- 
# directory (of .branches) named after the branch in question, changing 
# any forward slashes in the branch name into double-underscores. 


## Example: 
# 
# [phil/master] ~/site$ grep .branches .gitignore 
# .branches 
# 
# [phil/master] ~/site$ find .branches/ 
# .branches/ 
# .branches/phil__master 
# .branches/phil__master/sites 
# .branches/phil__master/sites/default 
# .branches/phil__master/sites/default/settings.branch.php 
# .branches/phil__media 
# .branches/phil__media/sites 
# .branches/phil__media/sites/default 
# .branches/phil__media/sites/default/settings.branch.php 
# 
# [phil/master] ~/site$ git checkout phil/media 
# Switched to branch 'phil/media' 
# Removing untracked per-branch files for: phil__master 
# `../.././sites/default/settings.branch.php' -> `./sites/default/settings.branch.php' 
# Adding untracked per-branch files for: phil__media 
# >f+++++++++ sites/default/settings.branch.php 


## Caveat: 
# 
# An early version of this script had issues whenever a git operation checked 
# out a detached HEAD, such that the .branches/.current_branch file contained 
# "HEAD" rather than the branch directory name, and so the intended untracked 
# files were not copied. 
# 
# I never got caught out by this, because my prompt always shows me the 
# .current_branch value (see comments at the end of the hook), so I notice 
# when it says HEAD unexpectedly; however I do not recall this happening at 
# all in the past few years, so I believe it is no longer a concern. 
# 
# If it were to happen to you, simply running git checkout (branch) for the 
# branch you are already on fixes it up. The log file may also help to debug 
# any such issues. 
# 
# n.b. It's feasible that git could update the HEAD ref without performing 
# a checkout (after initially checking out a detached head), but the cases 
# I've observed (and fixed) were associated with rebasing, where this script 
# had (undesirably) permitted its own processing to occur after an initial 
# checkout of a detached HEAD, and had then exited early (as intended when 
# rebasing) after the subsequent checkout of the eventual branch. The solution 
# was to improve the detection of the cases in which we wish to exit early, 
# to cover the former case as well as the latter. 


## Changelog: 
# 
# v1.1: Handle additional text following "rebase" in GIT_REFLOG_ACTION. 
#  Renamed $git_dir to $root (it's the working copy root, not .git) 
#  Log git environment vars even when aborting. 


## General information on Git post-checkout hooks: 
# 
# This hook is invoked when a git checkout is run after having updated 
# the worktree. The hook is given three parameters: the ref of the 
# previous HEAD, the ref of the new HEAD (which may or may not have 
# changed), and a flag indicating whether the checkout was a branch 
# checkout (changing branches, flag=1) or a file checkout (retrieving 
# a file from the index, flag=0). This hook cannot affect the outcome 
# of git checkout. 
# 
# It is also run after git clone, unless the --no-checkout (-n) option 
# is used. The first parameter given to the hook is the null-ref, the 
# second the ref of the new HEAD and the flag is always 1. 
# 
# This hook can be used to perform repository validity checks, 
# auto-display differences from the previous HEAD if different, or set 
# working dir metadata properties. 

############################################################################## 

head_old=$1 
head_new=$2 
flag=$3 

# n.b. pwd will be this working copy's root directory. 
root=$(pwd) 

# Debug log. 
log=".branches/post-checkout.log" 
echo "\n$(date)" >>${log} 2>&1 
if test -f .branches/.current_branch; then 
    echo ".current_branch: $(cat .branches/.current_branch)" >>${log} 2>&1 
else 
    echo ".current_branch (file missing)" >>${log} 2>&1 
fi 
echo "Old: $(git log --max-count=1 --decorate ${head_old} | head -1)" >>${log} 2>&1 
echo "New: $(git log --max-count=1 --decorate ${head_new} | head -1)" >>${log} 2>&1 

# Log the GIT environment variables. This is primarily to assist with finding 
# workarounds for any edge cases that might crop up. (This is how I discovered 
# GIT_REFLOG_ACTION.) 
set | grep GIT >>${log} 2>&1 

# Check the 'flag' parameter ($3). 
if test "$flag" != "1"; then # not a branch switch. 
    echo "$0 aborted (not a branch switch)." 2>&1 | tee -a ${log} 
    echo "Check ${log} for details." 
    exit 0 
fi 

# This hook is also invoked with flag=1 when rebasing, which we never want. 
# We only want to move the untracked files around when we have explictly 
# requested a checkout (which also means that the .current_branch file must 
# only ever be updated at those same times). 
if test "${GIT_REFLOG_ACTION##rebase}" != "${GIT_REFLOG_ACTION}"; then 
    echo "$0 aborted (GIT_REFLOG_ACTION indicated rebase)." 2>&1 | tee -a ${log} 
    echo "Check ${log} for details." 
    exit 0 
elif test -d "$root/.git/rebase-merge"; then 
    echo "$0 aborted (.git/rebase-merge indicated rebase)." 2>&1 | tee -a ${log} 
    echo "Check ${log} for details." 
    exit 0 
fi 

# Determine which .branches directory we were originally using. 
# There is no pre-checkout hook, but we can include a marker file amongst 
# the untracked files identifying the current branch name, and use that to 
# update the versions of the files under .branches from the current versions 
# before copying the new versions. 
cd "$root" 
if test -f .branches/.current_branch; then 
    oldbranch=$(cat .branches/.current_branch) 
    oldbranch_dir=".branches/$oldbranch" 
    if test -d "$oldbranch_dir"; then 
     echo "Removing untracked per-branch files for: $oldbranch" 
     cd "$oldbranch_dir" 
     find . -type f -print0 | xargs -0r -I{} mv -v -f ../../{} {} 
    fi 
fi 

# Establish the name of the newly checked-out branch. 
cd "$root" 
newbranch=$(git symbolic-ref -q HEAD) 
newbranch=${newbranch##refs/heads/} 
newbranch=${newbranch:-HEAD} 
newbranch=$(echo $newbranch | sed 's/\//__/') 
newbranch_dir=".branches/$newbranch" 

# Create/update marker file. 
test -d .branches || mkdir .branches 
echo $newbranch >.branches/.current_branch 
echo ".current_branch: $(cat .branches/.current_branch)" >>${log} 2>&1 

# Copy across the untracked files needed for the new branch. 
echo "Adding untracked per-branch files for: $newbranch" 

if ! test -d "$newbranch_dir"; then 
    echo "$newbranch_dir not found; nothing to update." 
    exit 0 
fi 

cd "$newbranch_dir" 
rsync -r -i . ../../ 

# You can also set a fancy prompt in bash to show you which branch you're in. 
# (Used to be super-useful when rebasing was a problem, but probably still 
# handy just for confirming that things are as they should be.) 
# PS1="${debian_chroot:+($debian_chroot)}\[email protected] [\$(cat /var/www/(site)/.branches/.current_branch | sed 's/__/\//')] \w\$ " 

# Local Variables: 
# outline-regexp: "^##" 
# eval: (outline-minor-mode 1) 
# eval: (while (re-search-forward "^## .+:" nil t) (outline-toggle-children)) 
# End: 

व्यक्तिगत तौर पर मैं वैश्विक करने के लिए ctags से स्विच बनाया कभी नहीं किया है, और मैं अपने टैग बनाए रखने के सामान्य समस्या के लिए एक नहीं बल्कि जानवर बल दृष्टिकोण का उपयोग तिथि, चलाने के लिए एक टाइमर का उपयोग करने के लिए है जो अप करने के लिए फ़ाइल एक एसिंक्रोनस खोल कमांड यह स्थापित करने के लिए कि क्या किसी भी फ़ाइल को TAGS से हाल ही में संशोधित किया गया है और यदि ऐसा है, तो एक नई TAGS फ़ाइल बनाएं। यदि नई फ़ाइल पुरानी फ़ाइल से अलग है तो मैं पुराने को प्रतिस्थापित करता हूं और Emacs की टैग पूर्णता तालिका को शून्य पर सेट करता हूं ताकि वह अगली बार TAGS फ़ाइल को फिर से पढ़ सके।

टैग्स फ़ाइल को पुनर्निर्माण करना इसलिए मेरा समाधान वर्तमान शाखा में कोड परिवर्तन करने के साथ-साथ दूसरी शाखा में स्विच करने के लिए है, इसलिए मेरे पास उद्देश्य के लिए मेरे पोस्ट-चेकआउट हुक का उपयोग करने का कोई कारण नहीं था मैंने यहां सुझाव दिया है। टाइमर आग लगने पर निर्भर करता है, कोड परिवर्तनों और TAGS फ़ाइल को पकड़ने के बीच कुछ मिनट की देरी हो सकती है, हालांकि, एक और तत्काल प्रतिक्रिया अच्छी होगी।

0

यही वह है जो मैंने अंत में किया था। मैंने टैग फ़ाइलों को गिट में जोड़ना शुरू कर दिया। लेकिन यह ब्रांचिंग और विलय के साथ अच्छी तरह से काम नहीं करता साबित हुआ और अंत में टैग फाइलों में मौजूदा शाखा में सभी प्रतीकों नहीं होंगे और वैसे भी कुछ भी नहीं। फिल्स के जवाब ने मुझे गिट हुक पर जांच करने के लिए प्रेरित किया।मैंने टैग फ़ाइलों को गिट वर्जनिंग से हटा दिया और पोस्ट-चेकआउट हुक बनाया जो शाखाओं को बदलने के दौरान मौजूद सभी टैग फ़ाइलों को चुपचाप हटा दिया। जब Emacs में हेल्म-gtags पता लगाता है कि उन्हें उत्पन्न करने के लिए कोई टैग फ़ाइल नहीं है। मेरी परियोजना के लिए जो काफी बड़ा है, इसमें लंबा समय नहीं लगता है। हेल्म-gtags यह भी पता लगाता है कि एक फ़ाइल बदल गई है और केवल इन परिवर्तनों के साथ टैग फ़ाइलों को स्वचालित रूप से अद्यतन करता है। तो अब मेरे पास एक ऐसी प्रणाली है जो वर्तमान शाखा में सभी प्रतीकों के साथ स्वचालित रूप से टैग फ़ाइलों को अद्यतित रखती है। अब तक यह अच्छी तरह से काम कर रहा है।

संबंधित मुद्दे