how to confirm that current git diff is one with current and last and not with current commit and any other

StackOverflow https://stackoverflow.com/questions/21359906

  •  02-10-2022
  •  | 
  •  

I am making a tool in python to push and obviously I would want to push the last commit so if I am checking the diff of the last I want to push but if the diff is not of current and last HEAD, then git push should not work.

How to check if the git diff is between current head and last head i.e. git diff HEAD^ HEAD and not any other ?

why I need functionality?

because Diff I am seeing is the diff I am going to send in email. however would that make sense I see a different diff and push the last commit .

which is why I am trying to figure out if diff being displayed is of current and last commit only then i should push else not.

有帮助吗?

解决方案

I sense a simple git status or git diff --cached would be enough to make sure that the last commit is indeed the last one, meaning there is no work in progress, some of it already added to the index, which could constitute a new commit.

If git status doesn't mention any file added to the index, then you can push your last commit.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top