Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How should I move changes from one commit to another?

Tags:

git

I have two commits on the same branch, one right after another. I added changes to file A to the first commit, and then I made some changes to other files and then made another commit. Now I want the changes to file A to be on the second commit rather than the first. What's the most elegant way?

like image 462
Rose Perrone Avatar asked Mar 05 '13 00:03

Rose Perrone


People also ask

What is the best way to modify your previous commit?

You can modify the most recent commit in the same branch by running git commit --amend. This command is convenient for adding new or updated files to the previous commit. It is also a simple way to edit or add comments to the previous commit. Use git commit --amend to modify the most recent commit.

How do you change committed changes?

What you can do is commit your current staged changes. Then stash the changes you don't want to commit using git stash and then revert the last commit using git reset HEAD~ . At this point you can make the modifications and recommit the changes (using git add . && git commit ).


1 Answers

I wrote a script to meet this purpose. You can checkout out it here.

Using the script it would be as simple as:

mv-changes HEAD~ HEAD fileA 
like image 106
Mikhail Golubtsov Avatar answered Sep 21 '22 22:09

Mikhail Golubtsov