git-branch

Show the original branch for a commit

陌路散爱 提交于 2019-11-26 19:57:19
问题 I've used git-blame to find a particular commit. Now I want to find the branch that it originally came from. (From there, I'll use the branch name to find the particular ticket) Let's define "original branch" as "the branch to which the commit was made before the branch was merged into any other branch". 回答1: Like the others said, if the branch you are looking for isn't local to the repository on which you are blaming this commit (e.g. a branch only in the personal repo of a distant developer

How do I “move” my commits from “no branch” to an actual branch?

不打扰是莪最后的温柔 提交于 2019-11-26 19:18:00
问题 I made a mistake, and started making commits "to the last tag", which lands my commits in "no branch". They should have been applied at the head of an already existing branch. I have not pushed my changes yet. I've found a few other question for when commits are in the wrong branch, but now I have no branch, so I don't know how to handle this. Preferably, I would like to erase my mistake entirely, and "move" my changes to the end of the right branch. If I must leave my mistake in the history,

What are the differences between local branch, local tracking branch, remote branch and remote tracking branch?

若如初见. 提交于 2019-11-26 19:17:16
I just started using Git and I got really confused between different branches. Can anyone help me to figure out what the following branch types are? local branches local tracking branches remote branches remote tracking branches What is the difference between them? And how do they work with each other? A quick demo code will be really helpful I guess. SNce A local branch is a branch that only you (the local user) can see. It exists only on your local machine. git branch myNewBranch # Create local branch named "myNewBranch" A remote branch is a branch on a remote location (in most cases origin

git how to find commit hash where branch originated from

徘徊边缘 提交于 2019-11-26 19:11:14
问题 Pretend I branched from my master branch to a topic branch, and then I did a few commits on my topic branch. Is there a command that tells me the commit hash on the master branch that my topic branch originated from? Ideally, I wouldn't have to know how many commits I've made ( trying to avoid HEAD^5 ). I've googled and SO'd around and can't seem to land on the answer. Thanks! 回答1: use git merge-base master your-branch to find the best common ancestor between two branches (usually the

What is the difference between git push.default=current and push.default=upstream?

99封情书 提交于 2019-11-26 18:53:12
问题 The man page for git-config lists these options for push.default: nothing - do not push anything. matching - push all matching branches. All branches having the same name in both ends are considered to be matching. This is the default. upstream - push the current branch to its upstream branch. tracking - deprecated synonym for upstream. current - push the current branch to a branch of the same name. In most cases I would assume that pushing to a branch's upstream branch would be the same as

How can I display the current branch and folder path in terminal?

余生颓废 提交于 2019-11-26 18:50:20
问题 I've been watching some of the Team Treehouse videos and they have a very nice looking terminal when working with Git. For example they have (something similar): mike@treehouseMac: [/Work/test - feature-branch-name] $ git add . mike@treehouseMac: [/Work/test - feature-branch-name] $ git commit -m "Some feature." mike@treehouseMac: [/Work/test - feature-branch-name] $ git checkout master mike@treehouseMac: [/Work/test - master] $ git status How can my terminal show me some useful information

What is the best (and safest) way to merge a Git branch into master?

断了今生、忘了曾经 提交于 2019-11-26 18:02:06
A new branch from master is created, we call it test . There are several developers who either commit to master or create other branches and later merge into master . Let's say work on test is taking several days and you want to continuously keep test updated with commits inside master . I would do git pull origin master from test . Question 1: Is this the right approach? Other developers could have easily worked on same files as I have worked btw. My work on test is done and I am ready to merge it back to master . Here are the two ways I can think of: A: git checkout test git pull origin

Git: How to list commits on this branch but not from merged branches

时光毁灭记忆、已成空白 提交于 2019-11-26 18:00:54
问题 Suppose your git commit history looks like this: A---B---C---D---E---F master \ / X---Y---Z topic Is it possible to have git list only the commits on master, A-F? In other words, if the commit was on a merged-in branch, I don't want it show. 回答1: git log has option --first-parent , so you won't get topic history. When merged from master , the master commits are the first parents in merge. Git log allows to display only those commits with --first-parent, so you get the right stuff. 回答2: There

How to determine when a Git branch was created?

不打扰是莪最后的温柔 提交于 2019-11-26 16:55:07
Is there a way to determine when a Git branch was created? I have a branch in my repo and and I don't remember creating it and thought maybe seeing the creation timestamp would jog my memory. Greg Bacon Use git show --summary `git merge-base foo master` If you’d rather see it in context using gitk, then use gitk --all --select-commit=`git merge-base foo master` (where foo is the name of the branch you are looking for.) Aaron As ponted out in the comments and in Jackub's answer , as long as your branch is younger than the number of days set in the config setting gc.reflogexpire (the default is

How do I copy a version of a single file from one git branch to another?

你离开我真会死。 提交于 2019-11-26 16:45:53
I've got two branches that are fully merged together. However, after the merge is done, I realise that one file has been messed up by the merge (someone else did an auto-format, gah), and it would just be easier to change to the new version in the other branch, and then re-insert my one line change after bringing it over into my branch. So what's the easiest way in git to do this? madlep Run this from the branch where you want the file to end up: git checkout otherbranch myfile.txt General formulas: git checkout <commit_hash> <relative_path_to_file_or_dir> git checkout <remote_name>/<branch