`
scm002
  • 浏览: 309819 次
社区版块
存档分类
最新评论

How to modify existing, unpushed or pushed commits?

 
阅读更多

https://stackoverflow.com/questions/179123/how-to-modify-existing-unpushed-commits

 

Amending the most recent commit message

git commit --amend

will open your editor, allowing you to change the commit message of the most recent commit. Additionally, you can set the commit message directly in the command line with:

git commit --amend -m "New commit message"

…however, this can make multi-line commit messages or small corrections more cumbersome to enter.

Make sure you don't have any working copy changes staged before doing this or they will get committed too. (Unstaged changes will not get committed.)

Changing the message of a commit that you've already pushed to your remote branch

If you've already pushed your commit up to your remote branch, then you'll need to force push the commit with

git push <remote><branch>--force
# Or
git push <remote><branch>-f

Warning: force-pushing will overwrite the remote branch with the state of your local one. If there are commits on the remote branch that you don't have in your local branch, you will lose those commits.

Warning: be cautious about amending commits that you have already shared with other people. Amending commits essentially rewrites them to have different SHA IDs, which poses a problem if other people have copies of the old commit that you've rewritten. Anyone who has a copy of the old commit will need to synchronize their work with your newly re-written commit, which can sometimes be difficult, so make sure you coordinate with others when attempting to rewrite shared commit history, or just avoid rewriting shared commits altogether.


Use interactive rebase

Another option is to use interactive rebase.
This allows you to edit any message you want to update even if it's not the latest message.

In order to do a git squash, follow these steps:

// X is the number of commits to the last commit you want to be able to edit
git rebase -i HEAD~X

Once you squash your commits - choose the e/r for editing the message

enter image description here

分享到:
评论

相关推荐

    uipath level 1 lesson 3参考答案.docx

    一下为部分题目: 2. The String.Format(“Input = {0} and Output = {1}”, “1”,”2”) expression returns which of ...6. Which activity can be used to modify the value of an existing cell in a DataTable?

    NWDI-how to modify the source code of ESS.zip

    How to modify the source code of SAP ESS

    HOW TO MODIFY EUCALYPTUS SOURCE CODE2.0.2

    EUCALYPTUS 2.0.2在ECLIPSE下实现修改.

    HOW TO MODIFY EUCALYPTUS SOURCE CODE 2.0.2

    EUCALYPTUS 2.0.2在ECLIPSE下实现修改

    Apress.Pro.Arduino.2013

    How to modify the Arduino to work with other chips How to simulate sensors for testing and debugging How to set up advanced XBee networks How to write Arduino libraries and share them with the ...

    ASP.NET Core 1.1 For Beginners: How to Build a MVC Website

    ASP.NET Core 1.1 For Beginners: How to Build a MVC Website by Jonas Fagerberg English | 19 May 2017 | ASIN: B071VX7KN4 | 411 Pages | PDF | 6.66 MB Want to learn how to build ASP.NET Core 1.1 MVC Web ...

    GWBasic3.22

    You will also be able to modify existing software that is written in GW-BASIC. &lt;br&gt;This guide is designed to help you use the GW-BASIC Interpreter with the MS-DOS?operating system. Section 1.5 ...

    Azure and Xamarin Forms 2018

    You'll review in detail how to build a Xamarin Form with Azure Client and modify an existing app to become a Xamarin Forms Client for Azure with offline synchronization. You then move on to third-...

    Instant.Oracle.Database.and.PowerShell.How-to

    You will also see how to execute and modify database procedures from PowerShell, run unattended, scheduled scripts, and automate database deployments using Oracle command line tools from PowerShell....

    Learn CSS in One Day and Learn It Well (Volume 2)

    Have you always wanted to learn ...How to modify text and font of a website How to create navigation bars How to create gorgeous looking tables to display your data

    How.to.Do.Everything.with.JavaScript

    This friendly, solutions-oriented guide is filled with step-by-step examples that illustrate how to write basic to advanced JavaScript applications, as well as modify existing scripts to suit ...

    Using the C++ Standard Template Libraries(Apress,2015)

    You'll learn how to create containers, and how iterators are used with them to access, modify, and extend the data elements they contain. You'll also learn about stream iterators that can transfer ...

    Android代码-buddysearch

    But for me, there were a lot of things that I wanted somehow to modify or improve, somewhere to simplify or to generify the code with creating Base-classes, somewhere to separate or move the code to ...

    practical-test-driven-development-c#7

    Now, write some new code or change some existing code to make all of the new/modified tests pass. If you do everything correctly, you should feel safe to make these changes as your existing test ...

    SQL Server 2014 Development Essentials - Masood-Al-Farooq, Basit A. [SRG].pdf

    delete the data using the DELETE statement, and how to update existing data using the UPDATE statement. This chapter also covers the SELECT…INTO, MERGE, and TRUNCATE TABLE statements, and it ...

    ASM_GUIDE_1_0_project

    It can be used to modify existing classes or dynamically generate classes, directly in binary form. Provided common transformations and analysis algorithms allow to easily assemble custom complex ...

    ASM_4_0_project

    It can be used to modify existing classes or dynamically generate classes, directly in binary form. Provided common transformations and analysis algorithms allow to easily assemble custom complex ...

    ASM_3_2_PROJECT

    It can be used to modify existing classes or dynamically generate classes, directly in binary form. Provided common transformations and analysis algorithms allow to easily assemble custom complex ...

    ASM_4_0_RC2_PROJECT

    It can be used to modify existing classes or dynamically generate classes, directly in binary form. Provided common transformations and analysis algorithms allow to easily assemble custom complex ...

Global site tag (gtag.js) - Google Analytics