0

I wish to create a git alias that revert a file from a specific commit. e.g. I have the following commits:

aaaaaaaa(HEAD -> DEV-10685) fixup! chore(cloud connector): something c bbbbbbbb chore(grpc): something b cccccccc refactor(agent communicator): something c dddddddd (origin/master, origin/HEAD) fix(config): something d 

by mistake, I commited a file mistake.txt that I didn't wish into cccccccc refactor(agent communicator): something c along with valid changes.

I wish to create a git alias that of the form: git revert-file mistake.txt cccccccc

to make things easier, I added here two unrelated git aliases, to demonstrate how to use function in git aliases

 rhm = reset --hard origin/master coom = ! "f() { git fetch && git co origin/master; }; f" 

I thought about something like:

  • create a fixup that remove the file and rebase and squash it
  • do a git rebase, edit the commit, and remove the file and finish the rebase

I didn't find an easy not risky way to do it, any ideas?

8
  • Why do you want to create an alias for a one-time operation? Commented Nov 6, 2023 at 1:01
  • Since I'm sure that I'm not special, and if it happens to me every once in a while, probably will end up to be worth the time to have such an alias. And everything that can be done with alias, might save human errors Commented Nov 6, 2023 at 1:03
  • Is this the workflow you're looking for? stackoverflow.com/a/32528151/11082165 Commented Nov 6, 2023 at 1:05
  • 2
    Okay, I think I understand now, you want the commit and the file to be a parameter. I was wondering why you would want to fix the same file in the same commit again after you have already fixed it. Commented Nov 6, 2023 at 1:08
  • @Brian61354270 yes. that's exactly the flow. Commented Nov 6, 2023 at 1:12

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.