1

when I pushed my changes from local feature branch to remote feature branch, I had whitespace changes that have also been pushed (now changing the code ownership to me). Now when I am trying to merge my feature branch into master, at the pull request level, I need to remove these whitespaces otherwise all these unmodified(except whitespaces) files will have my name tagged along.

May I know if there is a way to remove these whitespaces (or take my name from ownership) of specific files where the only changes made are whitespace changes? Each commit has several files. Any help is highly appreciated! Thanks!

user3923643
  • 113
  • 1
  • 2
  • 8
  • 2
    https://unix.stackexchange.com/questions/10277/ignore-whitespaces-changes-in-all-git-commands – Paul H Feb 10 '18 at 01:38
  • Files in git don't have a concept of ownership. Perhaps you're seeing the name of the author of the most recent change? – Paul Hicks Feb 10 '18 at 01:38
  • 1
    A general process you can follow is to create a new branch from the existing branch at the commit before the offending one, then rebase that commit into the new branch while ignoring whitespace (`git rebase --ignore-whitespace`). Then you delete the wrong branch and rename the new branch to the correct name. – Paul Hicks Feb 10 '18 at 01:41
  • I agree, rebase is the way to go. If you want to be more selective about the changes do an interactive rebase `git rebase -i ` and change `pick` to `edit` for any commit you'd like to change, and clean up the changes you don't want along the way. – wickdninja Feb 10 '18 at 02:10
  • Possible duplicate question with answer here https://stackoverflow.com/questions/3515597/add-only-non-whitespace-changes – ilooner Feb 11 '18 at 01:36
  • Thanks @PaulHicks and wickdninja for the responses. To be more specific, say I have a commit of 20 files and in which 6 files are just whitespace changes that has accidentally occurred during the merge. Now if I rebase that commit as you mentioned, will I be able to change only those 6 files and leave the rest untouched? – user3923643 Feb 12 '18 at 18:40
  • The files with no differences from one commit to the next will not be changed/committed (that is, if you (or git) edit a file several times and it ends up back where it started, then it is not added to the index/commit). So if you `rebase --ignore-whitespace`, you'll get a new commit with the same changes minus whitespace changes, fewer files will change, and git won't add them to the index/commit. – Paul Hicks Feb 12 '18 at 21:27

1 Answers1

0

I managed to remove all whitespaces from my PR using this method. What this will do is take the file from your main branch (without the whitespace) and insert it into your PR. After using this command, push the changes

git checkout origin/main -- nameOfYourFile

e.g.

git checkout origin/main -- ProductEnvironments/MakeApiCalls.cs

gabegi
  • 11
  • 2