在SourceTree Windows中编辑一个提交信息(已经推送到远程)。 |
您所在的位置:网站首页 › git修改提交人信息 › 在SourceTree Windows中编辑一个提交信息(已经推送到远程)。 |
百度翻译此文
有道翻译此文
问题描述
How do I edit an incorrect commit message in SourceTree without touching the command line? Additional details: This is not the latest commit. Everything was already pushed to Bitbucket. This is a private repository and I am the only collaborator. I don't mind losing any of the previous commits, as I can re-commit them anytime. I don't want however to lose any code modification ever made.Outcome: As it seems impossible at the moment according to your comments and replies, I'm going to create a new repository and start all over. Thanks all for your help! 推荐答案Here are the steps to edit the commit message of a previous commit (which is not the most recent commit) using SourceTree for Windows version 1.5.2.0: Step 1Select the commit immediately before the commit that you want to edit. For example, if I want to edit the commit with message "FOOBAR!" then I need to select the commit that comes right before it: Right-click on the selected commit and click Rebase children...interactively: Select the commit that you want to edit, then click Edit Message at the bottom. In this case, I'm selecting the commit with the message "FOOBAR!": Edit the commit message, and then click OK. In my example, I've added "SHAZBOT! SKADOOSH!" When you return to interactive rebase window, click on OK to finish the rebase: At this point, you'll need to force-push your new changes since you've rebased commits that you've already pushed. However, the current 1.5.2.0 version of SourceTree for Windows does not allow you to force-push through the GUI, so you'll need to use Git from the command line anyways in order to do that. Click Terminal from the GUI to open up a terminal. From the terminal force-push with the following command, git push origin -fwhere is the name of the branch that you want to push, and -f means to force the push. The force push will overwrite your commits on your remote repo, but that's OK in your case since you said that you're not sharing your repo with other people. That's it! You're done! 其他推荐答案On Version 1.9.6.1. For UnPushed commit. Click on previously committed description Click Commit icon Enter new commit message, and choose "Ammend latest commit" from the Commit options dropdown. Commit your message. 其他推荐答案If the comment message includes non-English characters, using method provided by user456814, those characters will be replaced by question marks. (tested under sourcetree Ver2.5.5.0) So I have to use the following method. CAUTION: if the commit has been pulled by other members, changes below might cause chaos for them. Step1: In the sourcetree main window, locate your repo tab, and click the "terminal" button to open the git command console. Step2: [Situation A]: target commit is the latest one. 1) In the git command console, input git commit --amend -m "new comment message"2) If the target commit has been pushed to remote, you have to push again by force. In the git command console, input git push --force[Situation B]: target commit is not the latest one. 1) In the git command console, input git rebase -i HEAD~nIt is to squash the latest n commits. e.g. if you want to edit the message before the last one, n is 2. This command will open a vi window, the first word of each line is "pick", and you change the "pick" to "reword" for the line you want to edit. Then, input :wq to save&quit that vi window. Now, a new vi window will be open, in this window you input your new message. Also use :wq to save&quit. 2) If the target commit has been pushed to remote, you have to push again by force. In the git command console, input git push --forceFinally: In the sourcetree main window, Press F5 to refresh. |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |