Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

May I list the files of the current commit?

Tags:

git

git-commit

Imagine that everytime I commit files, before I push them, I'd like to list them to check. How may I do that ?

I tried:

git ls-tree -r --name-only master
git ls-files -stage

If I edit a single file, add then commit it. If I try the above codes, it shows me all my files.

I want to list ONLY the files that will be pushed on the current commit.

like image 225
PlayHardGoPro Avatar asked Sep 13 '17 19:09

PlayHardGoPro


People also ask

How do I list all the files in a commit?

Solution. 2.1 git log to display all the commit_id, the first one is the last commit_id, copy it. 2.2 git show commit_id --name-only to display all the files committed in the specified commit_id. 2.3 Undo the last commit with git reset --soft HEAD~1 , move the mistakenly committed files back to the staging area.

How do I get a list of files changed in a commit?

To find out which files changed in a given commit, use the git log --raw command. It's the fastest and simplest way to get insight into which files a commit affects.

How do I list files in git?

If you want a list of files that ever existed use: git log --pretty=format: --name-only --diff-filter=A | sort - | sed '/^$/d'This command will list all the files including deleted files.

How can I see current commit messages?

Viewing a list of the latest commits. If you want to see what's happened recently in your project, you can use git log . This command will output a list of the latest commits in chronological order, with the latest commit first.


1 Answers

Git diff to the rescue on this one. You'll use the --name-only flag. To get the contents of the current commit, use this command:

#before stage
  git diff --name-only 
#staged changes before committing
  git diff --name-only --cached
#after committing
  git diff --name-only HEAD^ HEAD

If you want to see the files that you will be pushing if there is more than one commit, you'll need to specify your current branch head and the head on the remote

git diff --name-only remote/branch branch
like image 190
LightBender Avatar answered Jan 26 '23 18:01

LightBender