gitignore不会忽略配置文件

时间:2016-11-03 18:46:24

标签: git gitignore

我已经阅读了this question以及this one,但它们似乎并不适合我。

我有一个git项目,其目录结构如下:

myapp/
    src/
    .gitignore
    build/

myapp/.gitignore的位置:

### gitignore ###
build/

我现在需要添加一个顶级config目录,并希望为其本地开发/测试添加配置文件,但不希望它们已提交。我只想提交("空")config目录。所以我读了上面的这两个问题并尝试实施他们的建议。现在我的项目看起来像:

myapp/
    src/
    .gitignore
    build/
    config/
        .gitignore
        test.json

myapp/.gitignore的位置:

### gitignore ###
build/
!config/.gitignore

config/.gitignore只是:

!.gitignore

然而,当我做git add . -n(干跑)时,我看到了:

add '.gitignore'
add 'config/.gitignore'
add 'config/test.json'

...所以看起来它会尝试添加我的test.json配置文件。我只是想要添加配置目录,以便命令输出:

add '.gitignore'
add 'config/.gitignore'

我出错的任何想法(及其原因)?

1 个答案:

答案 0 :(得分:2)

public class ListviewAgendaAdapter extends ArrayAdapter<ObjectAgenda> { private int selected = -1; ArrayList<ObjectAgenda> items; private Activity context; public ListviewAgendaAdapter(Activity context, ArrayList<ObjectAgenda> items) { super(context, R.layout.singlerowagenda, items); this.context = context; this.items = items; } public void add(ObjectAgenda oa){ this.items.add(oa); } public void setData(ArrayList<ObjectAgenda> items) { this.items = items; notifyDataSetChanged(); } public void select(int position) { this.selected = position; notifyDataSetChanged(); } @Override public ObjectAgenda getItem(int position) { return items.get(position); } @Override public long getItemId(int position) { return position; } public void deleteRowFromUi(int position) { this.items.remove(position); notifyDataSetChanged(); notifyDataSetInvalidated(); } @Override public View getView(final int position, View convertView, ViewGroup parent) { ObjectAgenda o = items.get(position); final ViewHolder holder; View vi = convertView; if (vi == null){ LayoutInflater inflater = context.getLayoutInflater(); vi = inflater.inflate(R.layout.singlerowagenda, null);// e' preciso fazer o inflate pois a view nao ainda nao esta em activity alguma holder = new ViewHolder(); holder.tvIndice = (TextView) vi.findViewById(R.id.tvindice); holder.tvNomeMed = (TextView) vi.findViewById(R.id.tvnomemed); holder.butdesmarca = (Button) vi.findViewById(R.id.butdesmarcar); holder.butdesmarca.setTag(position); holder.butdesmarca.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Integer index = (Integer) view.getTag(); desmarca_agenda(index); } }); vi.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } if(selected != -1 && position == selected) { vi.setBackgroundColor(context.getResources().getColor(R.color.red)); }else vi.setBackgroundColor(context.getResources().getColor( R.color.white)); holder.tvIndice.setText(String.valueOf(o.getIndice())); holder.tvNomeMed.setText(o.getNome_med()); return vi; } static class ViewHolder { TextView tvIndice, tvNomeMed; Button butdesmarca; } private void desmarca_agenda(final Integer position) { JSONArray ja = new JSONArray(); ja.put(indice); String mot=textMot.getText().toString().trim(); if (TextUtils.isEmpty(mot)) mot="Não especificado"; ja.put(mot); JSONObject jsonBody = new JSONObject(); try { jsonBody.put("_parameters", ja); } catch (JSONException e) { e.printStackTrace(); } JsonObjectRequest jr = new JsonObjectRequest(Request.Method.POST, url, jsonBody, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { // TODO Auto-generated method stub String s = ""; try { JSONArray LResult = response.getJSONArray("result"); s = LResult.get(0).toString(); } catch (JSONException e) { e.printStackTrace(); } if (s.equals("true")) { deleteRowFromUi(position.intValue()); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { error.printStackTrace(); } }); Common.getInstance().addToReqQueue(jr, "jreq"); } 应包含:

public class AgendaMedFragment extends Fragment {
    private static final String TAG = AgendaMedFragment.class.getSimpleName();
    ListviewAgendaAdapter adapter;
    ArrayList<ObjectAgenda> items;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.agendamedfrag, null);

        final ListView listView = (ListView) view.findViewById(R.id.list_cons);
        View v = (View) view.findViewById(R.id.empty_cons);
        listView.setEmptyView(v);
        items = new ArrayList<ObjectAgenda>();
        adapter = new ListviewAgendaAdapter(getActivity(), items);
        listView.setAdapter(adapter);

        Button but_data_execute= (Button) view.findViewById(R.id.but_data_agenda_execute);
        but_data_execute.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                execute_get_agendamentos();
            }
        });

        execute_get_agendamentos();
        return view;
    }



    private void parseJSONResponseAgendamentos(JSONObject response) {
        try {

            JSONArray LResult = response.getJSONArray("result");
            String s = LResult.get(0).toString();
            JSONArray entries = new JSONArray(s);

            items.clear();
            for (int count = 0; count < entries.length(); count++) {
                JSONObject anEntry = entries.getJSONObject(count);

                String email = Common.getInstance().obag.getEmail();
                String senha = Common.getInstance().obag.getSenha();
                items.add(new ObjectAgenda(email, senha));
            }
            adapter.setData(items);
            adapter.notifyDataSetChanged();

        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }
    private void execute_get_agendamentos() {
        String url = Common.getServerURL() + "\"ag_get_ag\"";

        JSONArray ja = new JSONArray();
        String email = "email"
        String senha = "pass"
        ja.put(email);
        ja.put(senha);
        JSONObject jsonBody = new JSONObject();
        try {
            jsonBody.put("_parameters", ja);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        JsonObjectRequest jr = new JsonObjectRequest(Request.Method.POST, url,
                jsonBody, new Response.Listener<JSONObject>() {

            @Override
            public void onResponse(JSONObject response) {
                parseJSONResponseAgendamentos(response);

            }

        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                error.printStackTrace();
            }
        });

        Common.getInstance().addToReqQueue(jr, "jreq");
    }

}

即“忽略所有 config/.gitignore。”这样:

*
!.gitignore

只是说“不要忽略.gitignore”,但它并没有说 应该忽略其他任何内容。

(您在根!.gitignore 文件中也不需要.gitignore。)