git-branch

How to get the branch from tag name in Git?

泄露秘密 提交于 2020-02-04 01:29:33
问题 I am trying to get the branch name from a given tag. I tried git describe --tag <tag-name> but this doesn't provide me any branch name. I tried using gitk to show to the tags and branch but gitk doesn't show me the tag. When I list out the tags git tag -l I see the tag name exist in the list. I just want a simple command which can tell me the branch when tag name is provided. 回答1: Tags and Branches in Git are only Labels pointing to specific snapshot of your files. That being said, Tags ain't

Retrieving git branch name in prompt or Android gradle: on Jenkins it returns HEAD

蓝咒 提交于 2020-02-03 08:39:29
问题 In gradle I'd like to add both the current branch-name and commit-number as suffix to my versionName. (Why? Because when I build my app in Jenkins to release it in HockeyApp, it's useful to show what branch & commit that app was built from!) So when I enter this in command prompt, my current branch name is returned: git rev-parse --abbrev-ref HEAD Same happens when I use this line in Android gradle, using the code in either this answer, or as shown in this piece of gradle code: def

Retrieving git branch name in prompt or Android gradle: on Jenkins it returns HEAD

て烟熏妆下的殇ゞ 提交于 2020-02-03 08:35:09
问题 In gradle I'd like to add both the current branch-name and commit-number as suffix to my versionName. (Why? Because when I build my app in Jenkins to release it in HockeyApp, it's useful to show what branch & commit that app was built from!) So when I enter this in command prompt, my current branch name is returned: git rev-parse --abbrev-ref HEAD Same happens when I use this line in Android gradle, using the code in either this answer, or as shown in this piece of gradle code: def

git pull command output message meaning into which branch

我的未来我决定 提交于 2020-01-21 05:43:31
问题 Say there is a remote branch br1 checkout on the remote repo, and the master branch on a local repo. Command 1: If I do a " git pull origin br1:br1 " it pulls remote br1 into local br1 , and shows: 9188a5d..97d4825 br1 -> br1 9188a5d..97d4825 br1 -> origin/br1 command 2: If I do just a " git pull ", it will pull remote br1 into local master , but it shows only the following: 9188a5d..97d4825 br1 -> origin/br1 I'm expecting it also shows something like " br1 -> master ". Why it does not show

How can I avoid an accidental dcommit from a local branch

北慕城南 提交于 2020-01-19 12:42:19
问题 Sometimes, I create local branches in git, and I'd like to get a warning message when I try to dcommit from them. How can I prevent myself from accidentally dcommiting from a local branch? 回答1: An alternative to pre-commit hooks, if you're using Linux (or Git bash or Cygwin or similar), is to wrap git in a shell helper function. Add the below to your ~/.bashrc (for bash, Git bash) or ~/.zshrc (for zsh) file, or whatever the equivalent is for your shell: real_git=$(which git) function git { if

Git: Use two branches with same name from different remotes

試著忘記壹切 提交于 2020-01-16 03:58:10
问题 I'm using a repository which exists both on github and on an internal gitlab. I have set up two remotes: origin (github) and gitlab . How can I easily interact with the branch master of both remotes? What I've tried: git checkout --track gitlab/master -> error: A branch named 'master' already exists. git checkout -b master-gitlab --track gitlab/master -> worked, I now have a local branch master-gitlab and the console output tells me: master-gitlab set up to track remote branch master from

Switching branches in Git with external dependencies

拥有回忆 提交于 2020-01-14 10:37:19
问题 Has anyone had to deal with the issues of switching git branches in a project that has Maven (or any other external) dependencies? For example, suppose that in one branch I have a maven dependency, and in another I don't (or have a different version required). Would I have to re-import maven dependencies each time I switch branches or is there a better approach? 回答1: It actually depends on an IDE you're using. I haven't noticed any issue with this when using IntelliJ IDEA. It handles any pom

command to determine the upstream ref of the current HEAD?

≯℡__Kan透↙ 提交于 2020-01-12 15:18:46
问题 I'm looking for what I hope is the simple one line command to determine the the correct upstream ref for the currently checked out branch? Essentially something like git branch --remote HEAD which (if it worked) would convert the symbolic pattern HEAD to the current branch name, and then the option --remote then changes it to the ref of the remote-tracking branch. (But it doesn't do that!) If I have branch morehelp with a config of remote = origin merge = refs/heads/morehelp The simple

Why is “git branch” silent in new repositories?

天大地大妈咪最大 提交于 2020-01-11 06:41:13
问题 When you create a new repository and run git branch , it exits silently. For example: $ mkdir /tmp/foo; cd /tmp/foo; git init Initialized empty Git repository in /tmp/foo/.git/ $ git branch Why doesn't the command provide any output, or show the master branch? 回答1: TL;DR No branch heads exist yet. Detailed Explanation A Git repository has no branches until you make your first commit. A newly-initialized repository sets HEAD to refs/heads/master, but refs/heads/master won't exist or contain a

Move commits from master onto a branch using git

余生颓废 提交于 2020-01-09 06:04:30
问题 I'm trying to learn how to use Git effectively and I'm wondering how I should (good practice/bad practice?) solve the following case: Say I have the following chain of commits in master: Initial commit Commit 1 Commit 2 Commit 3 Then I realize that what's done in the last two commits is completely wrong and I need to start from Commit 1 again. Questions: How should I do that? Can I move Commit 2 and 3 to a separate branch to keep for future reference (say they weren't that bad after all) and