in Education by
I usually submit a list of commits for review. If I have the following commits: HEAD Commit3 Commit2 Commit1 ...I know that I can modify head commit with git commit --amend. But how can I modify Commit1, given that it is not the HEAD commit? Select the correct answer from above options

1 Answer

0 votes
by
 
Best answer
Show the last 4 commits in a text editor and find the commit you want to modify, git rebase -i @~4 Remember that @ is shorthand for HEAD, and ~ is the commit before the specified commit. Now, replace pick to e (edit) and save and close the file. Git rewinds that commit, allowing you to either: use the command, git commit --amend to make changes, or use the command, git reset @~ to discard the last commit, but not the changes to the files The second one is useful for doing more complex stuff like splitting into multiple commits. After that run the command, git rebase --continue, and then Git will replay the subsequent changes on top of your modified commit. You may be asked to fix some merge conflicts. For more information please go through the following tutorial to get more info about git:

Related questions

0 votes
    I wrote the wrong thing in a commit message. How can I change the message? The commit has not been pushed yet. Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    As asked in this question, I also want to know how to resolve a conflicting git stash pop without ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 2, 2022 in Education by JackTerrance
0 votes
    How do I revert from my current state to a snapshot made on a certain commit? If I do git log, then I get ... , i.e. commit 0d1d7fc? Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    Recently, I have been asked to cherry-pick a commit. So what does cherry-picking a commit in git mean? How do you do it? Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    I would like to know how to delete a commit. By delete, I mean it is as if I didn't make that commit, ... -hard HEAD. Is this correct? Select the correct answer from above options...
asked Feb 2, 2022 in Education by JackTerrance
0 votes
    I have a project consisting of a huge amount of data. Because of its size, I can't use a remote GIT repo and push/pull ... -ProjectGit | | |-objects |-project1 | |-refs | |-.git...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    My git workspace is dirty, there are some local modifications. When I use the command git pull origin master it ... Ansible git module? Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    I staged a few changes to be committed; how can I see the diff of all files which are staged for the next ... an alias for, right? Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    I staged a few changes to be committed; how can I see the diff of all files which are staged for the next ... an alias for, right? Select the correct answer from above options...
asked Feb 5, 2022 in Education by JackTerrance
0 votes
    I have a local git repo and when I do a git push, I need the repo to be pushed to my EC2 instance. ... heads/*:refs/remotes/origin/* Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    I cloned a Git repository, which contains about five branches. However, when I do git branch I only see one of ... staging * etc... Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    I used git pull and had a merge conflict: unmerged: _widget.html.erb You are in the middle of a conflicted merge. ... can I do this? Select the correct answer from above options...
asked Feb 2, 2022 in Education by JackTerrance
0 votes
    I created a local branch that I want to 'push' upstream. There is a similar question here on Stack ... the upstream repository? Select the correct answer from above options...
asked Feb 2, 2022 in Education by JackTerrance
0 votes
    I would prefer to write my commit messages in Vim, but it is opening them in Emacs. How do I configure Git ... for a single project. Select the correct answer from above options...
asked Feb 2, 2022 in Education by JackTerrance
0 votes
    How do you delete a Git tag that has already been pushed? Select the correct answer from above options...
asked Feb 2, 2022 in Education by JackTerrance
...