Question

Scenario Explained: I have done my functionalities and pushed to some git branch & shared the commit version to my Project manager. Later on, I realized that I missed out a functionality and I want to push it to the same branch without any commits being logged., The newly pushed commit should get appended to the last commit with the same commit version I shared to my Project Manager.

Was it helpful?

Solution

This is not possible.

The commit hash depends on several factors:

  • commit time
  • changes introduced
  • the parent commit
  • ...

See this question for further information: How does git compute file hashes?

So, if you introduce a new commit, you will always receive a new hash.

Since you already pushed your commits, create a new commit, enter an appropriate commit message and push this commit also.

Yes, you will have to tell your Project Manager to fetch again but what's wrong with amending a commit?

If you hadn't pushed your commit already, you would like to do

git commit --amend

but also this will lead to a different commit hash.

OTHER TIPS

Like eckes said, this is not possible.

There are several workarounds, depending on your needs.

1) If it is soon enough and noone else has commited yet, you may overwrite the tree whit git reset --hard and "avoid the branch passing trough that specific commit". This is good when you have something on the code that it is not suppose to be seen by others.

git reset --hard hashLastValidCommit
git add files
git commit -m"xxxx"
git push -f

Note: the commit it is still there, but it is no longer in any branch and it's quite hard to catch whitout the hash.

2) You may also do a rebase and melt those commits (the new and the incomplete one) into one. This is way more efficient than the previous step.

3) If you haven't pushed the commit yet, that's entirely another subject. Just do the ammend or reset, but the hash will change no matter what.

Here it is an interesting article about how hashes are created, this will give you a better view and put you on the right track.

http://alblue.bandlem.com/2011/08/git-tip-of-week-objects.html

Try

git commit --amend --no-edit.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top