我使用Git作为版本控制(目前是集中式工作流程,但我想转移到功能分支或gitflow工作流程)。我使用RStudio / Knitr来编译PDF文档,并想知道如何在PDF中自动包含当前的Git版本 - 如果可行的话?这样,当有人用我给他们的文件回复我时,我知道如何回到代码中的那一点。任何建议都将不胜感激,谢谢 - 玛丽。
编辑:关键字是我的想法,虽然根据这篇文章(gelato.unsw.edu.au/archives/git/0610/28891.html)不推荐。有关帮助程序脚本的建议吗? - 刚刚用户1420372
答案 0 :(得分:8)
这样做只是为了展示一个以坚果为例的例子。这是@Wanter Nuata的想法。
这是一个小小的编织医生:
foobar
我在新创建的本地git仓库中。
当我编织PDF时,我得到了这个:
所以你应该可以用它来为从它生成的git提交加水印。
或者,如果您擅长向项目添加另一个包依赖项,则可以使用---
output: pdf_document
---
```{r}
print(system("git rev-parse --short HEAD", intern = TRUE))
```
包:
git2r
给出了:
答案 1 :(得分:5)
使用git2r软件包的建议非常好。使用更多功能,您可以隔离实际的SHA。如果感兴趣,您还可以重新调整用途,例如,“作者”字段以获取文档标题中的SHA。
这是R Markdown文档:
private void getOnboardingCategories() {
showSpinnerDialog(true);
Response.Listener<JSONObject> responseListener = new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d(LOG_TAG, "CATEGORY RESPONSE: " + response.toString());
hideSpinnerDialog();
String code = response.optString("code");
if (code.equals("success")) {
if (response != null) {
JSONArray dataArray = response.optJSONArray("data");
int dataLength = dataArray.length();
for (int i = 0; i < dataLength; i++) {
JSONObject jObject = dataArray.optJSONObject(i);
if (jObject != null) {
CategoryType2 categoryType2 = new CategoryType2();
categoryType2.set_id(jObject.optString("_id"));
categoryType2.setName(jObject.optString("name"));
categoryType2.setApp_icon_data(jObject.optString("app_icon_data"));
categories.add(categoryType2);
}
}
}
}
if (isVisible())
sellAdapter.notifyDataSetChanged();
}
};
Response.ErrorListener errorListener = new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
Util.errorHandler(error, ctx);
}
};
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Method.GET, url,
null, responseListener, errorListener);
MyApplication.getInstance().addToRequestQueue(jsonObjectRequest, "onboarding");
}
哪个给出了