我知道有两种方法可以更改 git 中的提交消息。
第一个是git amend,它仅适用于最新的提交。由于我希望能够直接更改较旧的提交消息,因此这不是我想要的。
第二个是交互式变基,例如本答案中描述的,它也可以更改旧提交的提交消息。程序是使用
git rebase -i HEAD~n
Run Code Online (Sandbox Code Playgroud)
我必须手动计算n我的具体情况有多大,然后滚动浏览所有这些提交的列表并将一个提交从 更改为pick,reword最后键入新的提交消息并强制推送。
老实说,虽然这可行,但这样做非常复杂且乏味。所以我的问题是,是否有一种更易于使用的选项(可能以别名的形式),可以一步自动执行此过程?
理想情况下,我想要一个像这样的命令:
git reword <hash> -m "New commit message"
Run Code Online (Sandbox Code Playgroud)
然后用力推动。这可能吗?
编辑:我想摆脱交互性,因为我想以编程方式自动化程序中的一些 git 命令。在此过程中必须手动与 git 交互,这违背了这种自动化的目的。
我想使用 C++ 和 Win API 以编程方式创建 32 位彩色图标。为此,我使用了在此处找到的以下代码。
HICON CreateSolidColorIcon(COLORREF iconColor, int width, int height)
{
// Obtain a handle to the screen device context.
HDC hdcScreen = GetDC(NULL);
// Create a memory device context, which we will draw into.
HDC hdcMem = CreateCompatibleDC(hdcScreen);
// Create the bitmap, and select it into the device context for drawing.
HBITMAP hbmp = CreateCompatibleBitmap(hdcScreen, width, height);
HBITMAP hbmpOld = (HBITMAP)SelectObject(hdcMem, hbmp);
// Draw your icon.
//
// For this simple example, …Run Code Online (Sandbox Code Playgroud) 考虑以下代码片段:
// MyWindow.h
struct MyWindow
{
LRESULT CALLBACK myWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
static LRESULT CALLBACK myWindowProcWrapper(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
};
extern MyWindow *windowPtr; // windowPtr is initialized on startup using raw new
// MyWindow.cpp
MyWindow *windowPtr = 0;
LRESULT CALLBACK MyWindow::myWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_NCDESTROY:
delete windowPtr;
break;
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}
LRESULT CALLBACK MyWindow::myWindowProcWrapper(HWND hwnd, UINT msg, WPARAM wParam, …Run Code Online (Sandbox Code Playgroud) 鉴于以下C++代码:
#include <iostream>
int main()
{
const int i = 1;
*const_cast<int*>(&i) = 1; // Not allowed but doesn't do anything?
std::cout << i << "\n";
}
Run Code Online (Sandbox Code Playgroud)
问题:上面的代码是否调用UB(未定义的行为)?我知道抛弃const并为iUB中的结果赋值,因为我们不允许更改const变量的值.但是,在上面的代码中,我实际上没有更改 - 的值i- 那么,这仍然是UB吗?