git-branch

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

牧云@^-^@ 提交于 2019-11-26 06:03:42
问题 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? 回答1: Run this from the branch where you want the file to end up: git checkout otherbranch myfile.txt General

How to determine when a Git branch was created?

妖精的绣舞 提交于 2019-11-26 04:57:44
问题 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. 回答1: 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.) 回答2: As ponted out in the comments and in Jackub's answer, as long as your

Modified files in a git branch are spilling over into another branch

一曲冷凌霜 提交于 2019-11-26 04:47:33
I am working on a git repository with a master branch and another topic branch. I have switched to topic branch and modified a file. Now, if I switched to master branch that same file is shown as modified. For example: git status in git-build branch: # On branch git-build # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: cvsup_current # Switch to master branch [root@redbull builder_scripts (git-build)]# git co master M builder_scripts/cvsup_current Switched to branch "master" git status in master branch [root@redbull builder_scripts (master)]# git status #

How to add Git&#39;s branch name to the commit message?

℡╲_俬逩灬. 提交于 2019-11-26 04:36:38
问题 I need some help with a Bash script that will automatically add the git\'s branch name as a hash in commit messages. 回答1: Use the prepare-commit-msg or commit-msg githook. There are examples already in your PROJECT/.git/hooks/ directory. As a security measure, you will have to manually enable such a hook on each repository you wish to use it. Though, you can commit the script and copy it on all clones into the .git/hooks/ directory. 回答2: Here is my commit-msg script as an example: #!/bin/sh #

Move branch pointer to different commit without checkout

南楼画角 提交于 2019-11-26 04:29:28
问题 To move the branch pointer of a checked out branch, one can use the git reset --hard command. But how to move the branch pointer of a not-checked out branch to point at a different commit (keeping all other stuff like tracked remote branch)? 回答1: N.B. If you simply want to move a branch to another commit, the easiest way is git branch -f branch-name new-tip-commit as detailed by Chris Johnsen's answer. You can do it for arbitrary refs. This is how to move a branch pointer: git update-ref -m

Is there a way to lock a branch in GIT

99封情书 提交于 2019-11-26 04:25:02
问题 I have an idea of locking a repository from users pushing files into it by having a lock script in the GIT update hook since the push can only recognize the userid as arguments and not the branches. So i can lock the entire repo which is just locking a directory. Is there a way to lock a specific branch in GIT? Or is there a way an Update Hook can identify from which branch the user is pushing and to which branch the code is pushed? 回答1: The branch being pushed to is the first parameter to

cleaning up old remote git branches

若如初见. 提交于 2019-11-26 03:34:51
问题 Here is my git workflow. I work from two different computers (A and B) and store a common git remote in dropbox directory. Let\'s say I have two branches master and devel. Both are tracking their remote counterparts origin/master and origin/devel. Now while on computer A, I delete branch devel - both local and remote - as follows: git push origin :heads/devel git branch -d devel Now if I do git branch -a on computer A, I get master origin/HEAD origin/master I now go to computer B. Do git

How do I clone a specific Git branch? [duplicate]

一曲冷凌霜 提交于 2019-11-26 03:27:30
问题 This question already has an answer here: How do I clone a single branch in Git? 15 answers Git clone will behave copying remote current working branch into local. Is there any way to clone a specific branch by myself without switching branches on the remote repository? 回答1: git clone --single-branch --branch <branchname> <remote-repo> The --single-branch option is valid from version 1.7.10 and later. Please see also the other answer which many people prefer. You may also want to make sure

Remove tracking branches no longer on remote

六眼飞鱼酱① 提交于 2019-11-26 03:26:03
问题 Is there a simple way to delete all tracking branches whose remote equivalent no longer exists? Example: Branches (local and remote) master origin/master origin/bug-fix-a origin/bug-fix-b origin/bug-fix-c Locally, I only have a master branch. Now I need to work on bug-fix-a , so I check it out, work on it, and push changes to the remote. Next I do the same with bug-fix-b . Branches (local and remote) master bug-fix-a bug-fix-b origin/master origin/bug-fix-a origin/bug-fix-b origin/bug-fix-c

Using Git, show all commits that are in one branch, but not the other(s)

夙愿已清 提交于 2019-11-26 02:59:28
问题 I have an old branch, which I would like to delete. However, before doing so, I want to check that all commits made to this branch were at some point merged into some other branch. Thus, I\'d like to see all commits made to my current branch which have not been applied to any other branch [or, if this is not possible without some scripting, how does one see all commits in one branch which have not been applied to another given branch?]. 回答1: You probably just want git branch --contains branch