如何在git中获取HEAD的当前状态?

时间:2017-05-15 09:35:47

标签: git

例如,如果我在分支上,我想获得分支名称。但如果我处于分离的HEAD状态,我想获得提交ID。

基本上,我正在寻找.git/HEAD文件的接口。我知道我可以cat它,但也许有一个命令会为我做这件事(这样我就不必处理像GIT_DIR这样的边缘情况不在我身边{ {1}}等。)

1 个答案:

答案 0 :(得分:4)

如果您正在使用git completion https://github.com/git/git/blob/master/contrib/completion/git-completion.bash。通常会自动安装。

你可以打电话

MyReceiver post_r;
Context context;
String newValue;
public void refresh() {
    //your code in refresh.
    Log.i("PostRefresh", "Post:YES");
}

public void onPause() {
    super.onPause();

    LocalBroadcastManager.getInstance(context).unregisterReceiver(post_r);
}

public void onResume() {
    super.onResume();
    post_r = new MyReceiver();
    LocalBroadcastManager.getInstance(getActivity()).registerReceiver(post_r,
            new IntentFilter("EDIT_TAG_REFRESH"));
}
  // OnResuming get the details from second Fragment
private class MyReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        YourFirstFragment.this.refresh(); // presend Fragment Name

        String action = intent.getAction();
        st_value1= intent.getStringExtra("Key1");
        st_value2= intent.getStringExtra("Key2");
       // EITHER SET THE VALUES HERE OR IN REFERESH METHOD

    }
}

否则使用。

echo $(__git_ps1 '%s')