git diff --name-only and spaces #21723
-
Hi I have a commit that includes several files One of them is a text file that i would like to commit as new instead of the previous one. This file has allot of changes from the previous version - and the changes are not readble. I would like that, once i use git diff or git format-patch The diff file created - will delete the previous version of this specific file and add the entire modified file. As for the rest of the file commited - it will use the diff as it is is there a way to do it? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi @eshlomi1, Welcome to the Github Community Forum! This is a little triky, but i think we can get on it… From now on i will call B the commit that you have create last and A the previous commit, and also consider to start from the master branch. With a git log you can see the id of the commit , something like this:
Now create a branch from A with the git command
In my case i will use this:
(You can also use the HEAD^ for the commit id, this refer to the previous commit of the HEAD commit) Now i have this new branch called test.one and I want to import the file _ test.txt _ for example. The merge --squash we are going to use is the merge command but without commit:
This will import all the changes made with the commit B. Now you can take 2 ways:
Way 1 This works only if the main branch is not the master, if it is go to Way 2 below. Reset all the files:
And do wherever you want like create a new commit with only the test.txt. Do not delete the other branch before you’ve concluded. When you are sure to commit all the changes you want in this branch you can remove the other branch with this command:
And if you also have the same refs in the remote you need to use this:
And you have done. Way 2 Do your commits in this new branch. When you have done and you want this changes in the other branch you can checkout in the previous branch, here i will use the master:
Now you need to remove the old commit B and move to the previous one in this example we call that A:
Let’s merge the branch testOne:
Now you need to force push this master into the remote version:
(Be carefull to use this command because this update the remote history for you and all of your collaborators) This is it. Hope this helps, ask if you have more questions :slight_smile: -Gabriele- Mark helpfull posts with Accept as Solution to help other users locate important info. Don’t forget to give Kudos for great contents! |
Beta Was this translation helpful? Give feedback.
Hi @eshlomi1,
Welcome to the Github Community Forum!
This is a little triky, but i think we can get on it…
From now on i will call B the commit that you have create last and A the previous commit, and also consider to start from the master branch.
With a git log you can see the id of the commit , something like this:
Now create a branch from A with the git command
In my case i will use this:
(You can also use the H…