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 9154405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:25:22+00:00 2026-06-17T12:25:22+00:00

I have committed a change and forgot to add a file to the change

  • 0

I have committed a change and forgot to add a file to the change set. After other commits, I realized the file is now missing from a HEAD^4 commit.

How do I rewrite a previous commit to include the missing 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-06-17T12:25:23+00:00Added an answer on June 17, 2026 at 12:25 pm

    Use git rebase --interactive HEAD~4 and set edit option for the commit you’d like to amend.

    Remember that you should not modify commits pushed to the remote repository this way. It’s better to add a new commit with missing file in that case.


    To make this more clear, first stash any current changes with git stash. Then, git rebase --interactive HEAD~4. You get the following in a text editor (note that you’ll get 5 commits, in descending order):

    pick 123e123 fifth last commit message
    pick 321e122 fourth last commit message
    pick 1d23e3f third last commit message
    pick 987a987 second last commit message
    pick 8a8a8a8 last commit message
    

    Modify the change entry’s prefix from pick to edit. That’d be edit 321e122 ... for the OP.

    git rebase goes through the entries, in order. As there’s only one we’re changing, you’ll only have one entry to change. Now, add your files with git add, and git commit --amend to amend the current commit with those added files.

    Finally, git rebase --continue moves onto the next file. As there’s only one, the rebase is complete

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a file that I should have committed but forgot all about. I
I have committed to learning C now, I'm good with Python/PHP/Bash but I've decided
Assume you have a file which has been committed in your Git repo. You
The problem I just accidentally committed a change to a file that was only
I have solved some merge conflicts, committed then tried to Push my changes and
I have committed several files on GitHub but I want to pull only single
I have accidentally committed the .idea/ directory into git. This is causing conflicts everywhere
I have two ActiveRecord models of the same class: #1: represents the current committed
This is what happened: I have a branch A. On branch A I committed
I have changed several things over the last hour and committed them step by

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.