Laxmikant Ratnaparkhi
Laxmikant Ratnaparkhi

Reputation: 5023

How to check what I'm going to commit?

I was working on some feature development using Git. In between I have got some urgent bug, so needed to switch on develop branch from feature/2.8.0. So to do that I run following commands (from shell history):

 2002  git status 
 2003  git stash 
 2004  git checkout develop 
 2005  git status 
 2006  git pull
 2007  git pull origin develop

Now here is my git status:

$ git status
# On branch develop
# Your branch is ahead of 'origin/develop' by 1 commit.
#   (use "git push" to publish your local commits)
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   src/lib/eval/prvl_listed_securities_0000_hxx0401_init.erl
#   src/lib/eval/prvl_listed_securities_0000_hxx0401_proc.erl
#   src/view/eval/prvl_listed_securities_0000_hxx0401.html
nothing added to commit but untracked files present (use "git add" to track)

Here, I can see following lines :

>    # On branch develop
>    # Your branch is ahead of 'origin/develop' by 1 commit.
>    #   (use "git push" to publish your local commits)

From history, I haven't committed anything, How can I check what are my local commits needs to push?

Upvotes: 1

Views: 4598

Answers (3)

user12514849
user12514849

Reputation:

There are two separate issues here. Let's talk about the first (the title).

"How to check what I'm going to commit?"

You can use git status to view which files ...

  • You haven't added yet (with git add <file>). These are "untracked files".
  • You haven't committed yet. These are the "changes to be committed" that will be committed when you run git commit.

This example illustrates the difference.

<O.o> git status
On branch example-branch
Untracked files:
  (use "git add <file>..." to include in what will be committed)

    exampleFile.txt

nothing added to commit but untracked files present (use "git add" to track)
<O.o> git add exampleFile.txt 
<O.o> git status
On branch example-branch
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    new file:   exampleFile.txt

<O.o> git commit -m "touched exampleFile.txt"
[example-branch 8a2b990432] touched exampleFile.txt
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 exampleFile.txt
<O.o> git status
On branch example-branch
nothing to commit, working tree clean
<O.o> 

Now let's talk about the second (the last question).

"How can I check which local commits I need to push?"

For that you'll want to use git diff origin/master HEAD. If you have no changes staged for commit, you can safely leave off the HEAD part. If you want just a list of files and not the code diff, tack on the

--name-only option.

See also this thread: How can I see what I am about to push with git?

Upvotes: 2

user456814
user456814

Reputation:

You can use the following syntax to get a list of all local commits on branch X that haven't yet been pushed to the remote branch origin/X:

git log origin/X..X

The use is .. is an example of a commit range. You can read more about how to use them from the FREE online Pro Git book, in particular the section on commit ranges.

Upvotes: 2

m42e
m42e

Reputation: 148

Try: git show HEAD This shows the content of the commit from your current head

Upvotes: 2

Related Questions