git command to check if a repository has any uncommitted changes - branch

I need to know if there is a git command using which I can check if there are any uncommitted changes present in a branch for a given repository

If you are only interested in files which are part of the index, the following command shows concise info
git status -suno

http://supercollider.sourceforge.net/wiki/index.php/Developer_cheatsheet_for_git
refer this link for git commands.
show uncommited local changes:
git diff [file]

You might as well use gitk - The Git repository browser

Related

Intellij delete multiple local branches

Using Intellij IDE (I have version 2017.3.5) is there a way to delete multiple local git branches at once
You can delete multiple branches in IntelliJ IDEA directly.
Go to tab Git / Log. There open the Tree view on the left side. Check this picture:
Source: https://youtrack.jetbrains.com/issue/IDEA-131571
// Update Feb 2021:
As mojmir.novak pointed out here: https://stackoverflow.com/a/65954247/1546042 you can do this now in IntelliJ. To remove only merged branches, see answer below:
// Older update:
To clean-up (old) feature branches that have been merged to master you can use the terminal to clean it up.
To delete all local branches that are already merged into the currently checked out branch:
git branch --merged | egrep -v "(^\*|master|dev)" | xargs git branch -d
See https://stackoverflow.com/a/6127884/1546042 for more details.
Cleaning up using run config"
In order to clean up multiple branches at once, using intelliJ. You need to install the Bash Support plugin and use it to create a run config that executes a script with the above command.
Install BashSupport plugin
Create script with the command. (e.g. ~/scripts/clean-branches.sh)
Create a new Bash run config.
Link to the script created in step #2.
Provide working directory of the repo you want to clean.
Run it to clean the branches.
There is a Plugin available for this:
https://plugins.jetbrains.com/plugin/10059-git-branch-cleaner/
To use it once it's installed, in the main menu go to:
VCS > Git > Delete Old Branches
Have been through the pain of cleaning up the unused branches, and found this plugin.
https://plugins.jetbrains.com/plugin/10059-git-branch-cleaner/
But I was not able to see the VCS > Git menu on my Mac - IntelliJ
But was successful in finding a similar option under git > context-menu - Delete old branches...
I am not sure if there is a default option or this is because of the above-mentioned plugin.
Sharing to help others who don't have VCS > Git menu like in my case
It's easy to delete multiple branch on Git Extensions.
http://gitextensions.github.io/

How do I change ignore-paths on an existing git-svn repo?

I have an already existing git-svn repo with an ignore paths in my .config file that looks like this:
ignore-paths = ^(?!(Path1/Proj1|Path1/Proj2|Path2/Proj3))
This works well.
Someone added a new project in svn that I now need in my git repo.
If I change ignore-paths to what's below and issue a fetch or a rebase, I never see Path2/Proj4
ignore-paths = ^(?!(Path1/Proj1|Path1/Proj2|Path2/Proj3|Path2/Proj4))
In the past, I've always given up and blasted away my git repo and recreated it. Is there a better way?
After editing the ignore-paths you need to
git svn reset -r <n> -p # where <n> is the SVN revision where the new path was added.
git svn fetch
git rebase # or reset
Reference git-svn(1):
reset
Undoes the effects of fetch back to the specified revision.
This allows you to re-fetch an SVN revision. Normally the
contents of an SVN revision should never change and reset
should not be necessary. However, if SVN permissions change,
or if you alter your --ignore-paths option, a fetch may fail
with "not found in commit" (file not previously visible) or
"checksum mismatch" (missed a modification). If the problem
file cannot be ignored forever (with --ignore-paths) the only
way to repair the repo is to use reset.
Only the rev_map and refs/remotes/git-svn are changed (see
$GIT_DIR/svn/*\*/.rev_map.* in the FILES section below for details).
Follow reset with a fetch and then git reset or git rebase to
move local branches onto the new tree.

Working with GIt without branches

I am trying to work with GIT, without creating private branches.
What that means is I directly work on my cloned repository (master)
Now, Is that the right way to use GIT? I run into many issues related to updating my repository (GIT PULL / GIT FETCH). And most of the time, I am not able to use GIT Merge.
Is there a particular way in which i can use GIT MERGE, GIT PULL, and GIT FETCH. That will help me?
Looks like the best way to work with GIT is have branches.
Branch 1
GIT Commit
GIT PUSH
GIT MERGE master ( to fetch the newer changes)
Branch 2
GIT Commit
GIT PUSH
master
GIT Merge branch1
GIT Merge branch2
I dont think there any other way. Please correct me if i am wrong?
Jan Krueger's extended cheat sheet will help you cover the basics, and will expose you some common commands for using git.
IMO, git is a brilliant DVCS. If you have time; take a look at the structure of git and try to catch the ideas behind its design. For example this Tech Talk by Linus Torvalds.
Note: It looks like you are missing some core ideas behind using git, so please try to learn general approach of git before tackling with commands.
Note 2: As being a stalker, you seem to have general problems with git. So I repeat my advice once more. Learn basics, complete a tutorial, read/listen/watch a few useful source from notable people about git.
Also read about git stash. It saves your local uncommitted changes so you can pull cleanly. Then run git stash pop to replay those changes on top.

Getting current Git commit version from within Rails app?

How can I retrieve the current Git commit version from within a Ruby on Rails app?
Want to display the Git version (or maybe the last 6 letters or so) to serve as an App version.
Like #meagar said, use backticks to execute the shell command from within your app, but you may find these two commands more useful:
Full hash:
git rev-parse HEAD
First 7 characters of hash:
git rev-parse --short HEAD
You can invoke the git command from within your script:
commit = `git show --pretty=%H`
puts commit
Depending on your environment you may want to use the full path to the git binary, and possibly specify the GIT_DIR via an environment variable or --git-dir.
A more robust solution would be git show --pretty=%H -q. The -q flag quiets the output.
In order to remove the newline that is part of the output, you can use chomp. For example: system('git show --pretty=%H -q').chomp
The selected answer has the potential to actually return the diff when the commit is not a merge commit. Verified on git version 2.16.2.windows.1.
I presume that you want to include the app version in your HTML somewhere? The prerequisite is that you are deploying your repo with Capistrano in the default manner (you are uploading the repo, not sending up an archive file).
You can add some code to the Rails initializer as outlined here. That approach will get the SHA1 from the last commit, and make it available as an environment variable.
The other way to do it is have you Capistrano task generate a static file in the public directory with the commit SHA in it. You could include other info in this file that seems useful.

How can you use git-svn to clone parts of an SVN repo, but still get all the branches

Is there any way to use git-svn to clone only some folders of an SVN repo structure. I'm trying to clone a repo that has some crazy big binary files and a number of subfolders that are just plain useless. I've tried using the --ignore-paths option, but my clone seemed to just stall out doing nothing for an extremely long time. Have any of you managed to make --ignore-paths work? I can't find much on the webs where anyone else is running into this. Maybe I'm the only one.
We've used the "ignore-paths" feature to ignore certain directories in a svn repo:
[svn-remote "svn"]
ignore-paths = ^(((branches|tags)/[^/]+|trunk)|)(huge/|mobile/)
This config ignores the "huge" and "mobile" subdirs of the repository in trunk, all branches and all tags.
Perhaps you can illustrate the structure of your Subversion repository to make it easier for us to suggest some solutions.
Are you trying to git svn clone the entire repository from the root-url? Have you tried cloning smaller parts of the repo, and then perhaps grafting several clones together?
The most success I've had here is to manually create branches in git that mirror the SVN remote repository when necessary. The process has been the following:
Update .git/config file with:
[svn-remote "svn-branch-alias"]
url = http://svn/branches/crazybranchname/craziername/url/
fetch = :refs/remotes/git-branch-name
From the command line type: git svn fetch 'svn-branch-alias' to collect the SVN branch data into your local git repo.
Then type: git checkout 'git-branch-name' to go into a headless mode.
Finally type: git checkout 'my-local-git-branch-name' to create move head to the latest submission in that branch and create a local branch alias you can use.
You can now commit and dcommit as usual and still switch between various local git branches and your manually created SVN mirrors using the usual mechanisms.