Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7398899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T03:55:51+00:00 2026-05-29T03:55:51+00:00

I just realized that I left out a file that I was supposed to

  • 0

I just realized that I left out a file that I was supposed to add to a commit like 5 commits back. In the commit message I said that the file was included, and I don’t feel like doing a new commit with the text “Oops forgot to add this file in commit #XXXXX”

What’s the best way to edit a previous commit so I can add the file?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T03:55:52+00:00Added an answer on May 29, 2026 at 3:55 am

    Commit your fix, then use git rebase --interactive to reorder your commits and squash the two commits together. See the git book for details.

    Note that doing this is bad idea if those commits have been pushed somewehere already, since you will change the repository history.

    An example session could look like this:

    % git init
    Initialized empty Git repository in /home/user/repo/.git/
    % echo "A line" > a.txt
    % echo "A line" > b.txt
    % git add a.txt b.txt
    % git commit -m "Initial commit"
    [master (root-commit) c6329d0] Initial commit
     2 files changed, 2 insertions(+), 0 deletions(-)
     create mode 100644 a.txt
     create mode 100644 b.txt
    

    Your incomplete commit:

    % echo "Another line" >> a.txt
    % git add a.txt
    % git commit -m "Important changes"
    [master 0d28cfa] Important changes
     1 files changed, 1 insertions(+), 0 deletions(-)
    

    Some other commit:

    % echo "Yet another line" >> b.txt
    % git add b.txt
    % git commit -m "Other changes"
    [master 96a092d] Other changes
     1 files changed, 1 insertions(+), 0 deletions(-)
    

    Notice that you’ve forgotten somthing:

    % echo "Important line forgotten previously" >> a.txt
    % git add a.txt
    % git commit -m "Oops"
    [master 9dce889] Oops
     1 files changed, 1 insertions(+), 0 deletions(-)
    

    Fix the history with git rebase -i:

    % git rebase -i HEAD~3
    

    You will be put into your editor of choice with contents similar to the following:

    pick 0d28cfa Important changes
    pick 96a092d Other changes
    pick 9dce889 Oops
    

    Change it so that the “oops” commit is moved one line above and change pick to squash (or just s) to combine it with the preceding commit:

    pick 0d28cfa Important changes
    s 9dce889 Oops
    pick 96a092d Other changes
    

    Then save the file and exit the edit. This will pop up another editor, where you can edit the commit message for the combined commit. It will look like this:

    # This is a combination of 2 commits.
    # The first commit's message is:
    
    Important changes
    
    # This is the 2nd commit message:
    
    Oops
    

    Change it as you feel is appropriate, then save and exit.

    Finally, check that the new commit indeed is a combination of the two commits:

    % git log -p HEAD~2..HEAD~1
    commit 7a4c496956eb269c551bbf027db8b0f2320b65e4
    Author: User Name <user@host.tld>
    Date:   Fri Feb 3 22:57:31 2012 +0100
    
        Important changes
    
    diff --git a/a.txt b/a.txt
    index 8d7158c..54df739 100644
    --- a/a.txt
    +++ b/a.txt
    @@ -1 +1,3 @@
     A line
    +Another line
    +Important line forgotten previously
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just realized that I left one word in the commit message of a
I just realized that this piece of code works well in Firefox but not
I just realized that the MySQLWorkBench destroys the target (makes a replacement) when performing
I just realized that I need to synchronize a significant amount of data collection
I just realized that the method Element.getElementsByTagName(someTagName) returns a nodelist of all elements in
I just realized that i may not be following best practices in regards to
I just realized that when i start a task from within a task and
I just realized that my app, with over 300 users still using an Android
I've just realized that when I use write.table() for saving a data frame in
I had the sample facebook login implementation, and just realized that it stopped working:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.