In git, obtain commits using git log with path
Asked Answered
P

2

9

I would like to obtain the last 10 commits using git log specifying the path of my repository. I used the option -path but I have "is outside repository" error

 git log --no-merges -10 -p /home/my_folder/git/repo

 fatal: /home/my_folder/git/repo: '/home/my_folder/git/repo' is outside repository

The comand is running for example in the folder /home

Puzzle answered 2/7, 2015 at 7:55 Comment(0)
J
17

Git assumes that the current working directory is inside the repository you want to operate on. When running a git command from outside the repository directory hierarchy, you can use the global -C option to git to specify which repository to use:

git -C /home/my_folder/git/repo log --no-merges -10 -p

Usually it's probably easier to simply cd to your repository before running git commands.

Jueta answered 2/7, 2015 at 8:16 Comment(2)
When running a git command from outside the repository directory hierarchy [...] Do you mean "from outside any repo"? The error message indicates that the OP runs that git log command from within some repo; otherwise s/he would have gotten fatal: Not a git repository (or any of the parent directories): .git.Delibes
@Jubobs: As stated in the first sentence of my answer, I meant from outside the repo you want to operate on. Whether you are in a different repo or not is immaterial – you will have to tell git what repository to use either way.Jueta
O
1

It's worth noting that the -C flag for git log only appeared starting from git 1.8.5 and up https://git-scm.com/docs/git/1.8.5

For older versions of git here are your options:

1.Manually move to the directory:

cd /home/my_folder/git/repo && git log --no-merges -10 && cd - 

2.Specify the --git-dir parameter:

git --git-dir /home/my_folder/git/repo/.git log --no-merges -10
Orthodontia answered 10/3, 2017 at 12:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.